pub async fn terminate_all_instances(
pool: &Pool<MySql>,
app_id: i64,
) -> Result<()>
Expand description
Terminates all running instances for a specific application.
This function marks all running instances of an application as ‘terminated’. It’s typically used during application shutdown, maintenance, or redeployment scenarios when all compute resources need to be released.
§Arguments
pool
- Database connection pool for executing the queryapp_id
- Unique identifier of the application whose instances to terminate
§Returns
Ok(())
- Successfully marked instances as terminatedErr(anyhow::Error)
- Failed to terminate instances
§Important
This function only updates the database records to reflect termination. The actual termination of compute resources should be handled by a separate process that reacts to these status changes.
§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.
§Use Cases
Common scenarios for using this function include:
- Application shutdown or decommissioning
- Emergency resource release during cost overruns
- Preparing for maintenance or major version upgrades
- Responding to security incidents requiring isolation