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.rs20
1 files changed, 20 insertions, 0 deletions
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<Vec<(Uuid, Uuid)>, 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(