summaryrefslogtreecommitdiff
path: root/makima/src/db/repository.rs
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db/repository.rs')
-rw-r--r--makima/src/db/repository.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs
index 9ec5275..9dedc14 100644
--- a/makima/src/db/repository.rs
+++ b/makima/src/db/repository.rs
@@ -5535,6 +5535,61 @@ pub async fn clear_orchestrator_task(
Ok(())
}
+/// Link a task to a step without changing step status.
+pub async fn link_task_to_step(
+ pool: &PgPool,
+ step_id: Uuid,
+ task_id: Uuid,
+) -> Result<(), sqlx::Error> {
+ sqlx::query(
+ r#"
+ UPDATE directive_steps
+ SET task_id = $2
+ WHERE id = $1
+ "#,
+ )
+ .bind(step_id)
+ .bind(task_id)
+ .execute(pool)
+ .await?;
+ Ok(())
+}
+
+/// Set a step to 'running' status (after its task has been dispatched).
+pub async fn set_step_running(
+ pool: &PgPool,
+ step_id: Uuid,
+) -> Result<(), sqlx::Error> {
+ sqlx::query(
+ r#"
+ UPDATE directive_steps
+ SET status = 'running', started_at = COALESCE(started_at, NOW())
+ WHERE id = $1
+ "#,
+ )
+ .bind(step_id)
+ .execute(pool)
+ .await?;
+ Ok(())
+}
+
+/// Get pending directive tasks (tasks with directive_id that are still pending).
+pub async fn get_pending_directive_tasks(
+ pool: &PgPool,
+) -> Result<Vec<Task>, sqlx::Error> {
+ sqlx::query_as::<_, Task>(
+ r#"
+ SELECT * FROM tasks
+ WHERE directive_id IS NOT NULL
+ AND status = 'pending'
+ AND daemon_id IS NULL
+ ORDER BY created_at
+ "#,
+ )
+ .fetch_all(pool)
+ .await
+}
+
/// Get the max generation number for steps in a directive.
pub async fn get_directive_max_generation(
pool: &PgPool,