pub async fn create_instance(
pool: &Pool<MySql>,
app_id: i64,
instance_type: &str,
) -> Result<Instance>
Expand description
Creates a new compute instance for an application.
This function provisions a new compute instance for an application with the specified instance type. The instance is initially created with a ‘provisioning’ status and ‘running’ instance_status.
§Arguments
pool
- Database connection pool for executing the queryapp_id
- Identifier of the application this instance belongs toinstance_type
- Type of instance to create (e.g., ‘small’, ‘medium’, ‘large’)
§Returns
Ok(Instance)
- Successfully created instance recordErr(anyhow::Error)
- Failed to create instance record
§Transaction Handling
This function uses a database transaction to ensure atomicity of the operation. If any part of the operation fails, the entire operation is rolled back.
§State Model
The instance is created with:
status
: ‘provisioning’ - Indicates the instance is being set upinstance_status
: ‘running’ - Indicates the intended operational state
These states will be updated as the instance progresses through its lifecycle.