summaryrefslogtreecommitdiff
path: root/makima/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'makima/src/db')
-rw-r--r--makima/src/db/repository.rs20
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,