Function create_instance

Source
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 query
  • app_id - Identifier of the application this instance belongs to
  • instance_type - Type of instance to create (e.g., ‘small’, ‘medium’, ‘large’)

§Returns

  • Ok(Instance) - Successfully created instance record
  • Err(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 up
  • instance_status: ‘running’ - Indicates the intended operational state

These states will be updated as the instance progresses through its lifecycle.