From 579c983d3efb8f1414ffb45b9e031f741cce5f76 Mon Sep 17 00:00:00 2001 From: soryu Date: Fri, 23 Jan 2026 23:52:35 +0000 Subject: Add resume to daemon tasks --- makima/src/db/repository.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'makima/src/db/repository.rs') diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index da44899..d3e4c56 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -823,6 +823,26 @@ pub async fn get_pending_tasks_for_contract( .await } +/// Get all contracts that have pending tasks awaiting retry. +/// Returns tuples of (contract_id, owner_id) for contracts with retryable tasks. +pub async fn get_all_pending_task_contracts( + pool: &PgPool, +) -> Result, sqlx::Error> { + sqlx::query_as::<_, (Uuid, Uuid)>( + r#" + SELECT DISTINCT contract_id, owner_id + FROM tasks + WHERE contract_id IS NOT NULL + AND status = 'pending' + AND is_supervisor = false + AND retry_count < max_retries + ORDER BY owner_id, contract_id + "#, + ) + .fetch_all(pool) + .await +} + /// Mark a task as pending for retry after daemon failure. /// Increments retry count and adds the failed daemon to exclusion list. pub async fn mark_task_for_retry( -- cgit v1.2.3