diff options
| author | soryu <soryu@soryu.co> | 2026-02-12 19:12:36 +0000 |
|---|---|---|
| committer | soryu <soryu@soryu.co> | 2026-02-12 19:12:36 +0000 |
| commit | a6d40de1be0f8ae1ba938acb7875ebcf2b3b18e7 (patch) | |
| tree | 9d657c2d77fca9c9a033cf86efcbf06a4d3eb8da /makima/src/db | |
| parent | ffbd8fed748ff4b60c53ee6ac54d7cf0548a7048 (diff) | |
| download | soryu-a6d40de1be0f8ae1ba938acb7875ebcf2b3b18e7.tar.gz soryu-a6d40de1be0f8ae1ba938acb7875ebcf2b3b18e7.zip | |
Fix PR creation task for directives to be atomic
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/repository.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 127f4cd..a79818f 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -5229,7 +5229,25 @@ pub async fn get_completion_tasks_to_check( .await } -/// Assign a completion task to a directive. +/// Atomically claim a directive for completion by setting a placeholder completion_task_id. +/// Returns true if the claim was successful (no other task already claimed it). +pub async fn claim_directive_for_completion( + pool: &PgPool, + directive_id: Uuid, + task_id: Uuid, +) -> Result<bool, sqlx::Error> { + let result = sqlx::query( + r#"UPDATE directives SET completion_task_id = $2, updated_at = NOW() + WHERE id = $1 AND completion_task_id IS NULL"#, + ) + .bind(directive_id) + .bind(task_id) + .execute(pool) + .await?; + Ok(result.rows_affected() > 0) +} + +/// Assign a completion task to a directive (unconditional update). pub async fn assign_completion_task( pool: &PgPool, directive_id: Uuid, |
