pub async fn update_instance_status(
pool: &Pool<MySql>,
id: i64,
status: &str,
instance_status: &str,
container_id: Option<&str>,
node_name: Option<&str>,
) -> Result<Instance>
Expand description
Updates the status and details of an existing instance.
This function modifies an instance record to reflect its current state and associated runtime information. It’s typically called during the instance lifecycle as it changes state or is assigned to specific infrastructure.
§Arguments
pool
- Database connection pool for executing the queryid
- Unique identifier of the instance to updatestatus
- New provisioning status (e.g., ‘provisioning’, ‘running’, ‘failed’)instance_status
- New operational status (e.g., ‘running’, ‘stopped’, ‘terminated’)container_id
- Optional identifier of the container running the instancenode_name
- Optional name of the node hosting the instance
§Returns
Ok(Instance)
- Successfully updated instance recordErr(anyhow::Error)
- Failed to update instance
§Status Model
The instance has two status fields:
status
: Represents the provisioning lifecycle (provisioning, running, failed)instance_status
: Represents the operational state (running, stopped, terminated)
§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.