pub async fn count_running_instances(
pool: &Pool<MySql>,
app_id: i64,
) -> Result<i64>
Expand description
Counts the number of running instances for a specific application.
This function returns the total count of instances in the ‘running’ state for an application. It’s more efficient than fetching all instances and counting them, especially when only the count is needed.
§Arguments
pool
- Database connection pool for executing the queryapp_id
- Unique identifier of the application
§Returns
Ok(i64)
- Successfully retrieved count of running instancesErr(anyhow::Error)
- Failed to count running instances
§Use Cases
Common use cases include:
- Auto-scaling decisions based on current instance count
- Monitoring application capacity
- Enforcing instance limits based on account tier
- Billing calculations based on active instance time