diff options
| author | soryu <soryu@soryu.co> | 2026-02-09 14:39:36 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-09 14:39:36 +0000 |
| commit | bfa7bd8d7609397f570f1cd9b83d2269abc0ed63 (patch) | |
| tree | 71e4e3decb5b07550427472079dfddffcc5c3753 /makima/src/db | |
| parent | a2646a828febbdac798a206655a15eae7e463bca (diff) | |
| download | soryu-bfa7bd8d7609397f570f1cd9b83d2269abc0ed63.tar.gz soryu-bfa7bd8d7609397f570f1cd9b83d2269abc0ed63.zip | |
Add directive task progression
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/repository.rs | 55 |
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, |
