Skip to main content

stormchaser_engine/handler/step/
quota.rs

1use anyhow::Result;
2use serde_json::Value;
3
4/// Releases the quota acquired for a specific step instance, marking it as completed or failed in the quota system.
5pub async fn release_step_quota_for_instance(
6    executor: &mut sqlx::PgConnection,
7    run_id: stormchaser_model::RunId,
8    step_id: stormchaser_model::StepInstanceId,
9) -> Result<()> {
10    let row: Option<(String, Value)> =
11        crate::db::steps::get_step_type_and_spec(&mut *executor, step_id)
12            .await
13            .ok();
14
15    if let Some((step_type, spec)) = row {
16        let (cpu, mem) = crate::resource_utils::get_step_resource_requirements(&step_type, &spec);
17        if cpu > 0.0 || mem > 0 {
18            let _ = crate::db::release_step_quota(&mut *executor, run_id, cpu, mem).await;
19        }
20    }
21
22    Ok(())
23}