diff --git a/crates/utopia-store/src/jobs.rs b/crates/utopia-store/src/jobs.rs index 8206f8a7d..00d88871d 100644 --- a/crates/utopia-store/src/jobs.rs +++ b/crates/utopia-store/src/jobs.rs @@ -341,6 +341,12 @@ pub async fn status_in_kb(pool: &PgPool, kb_id: Uuid, id: i64) -> AppResult AppResult> { let job = sqlx::query_as( "UPDATE jobs SET status = 'running', locked_at = now(), @@ -348,7 +354,10 @@ async fn claim_one(pool: &PgPool) -> AppResult> { WHERE id = ( SELECT id FROM jobs WHERE status = 'queued' AND run_at <= now() - ORDER BY run_at + ORDER BY + CASE WHEN kind IN ('sync_source', 'process_document', 'embed_ontology') + THEN 0 ELSE 1 END, + run_at FOR UPDATE SKIP LOCKED LIMIT 1 )