Prioritize newest AI jobs
All checks were successful
CI / test (push) Successful in 15s
Build and Deploy / build-and-deploy (push) Successful in 23s

This commit is contained in:
Grendgi
2026-06-08 17:48:02 +03:00
parent 3ecdcd395e
commit 16ff6ecb5e
4 changed files with 16 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
DROP INDEX IF EXISTS ai_jobs_pending_claim_idx;
CREATE INDEX IF NOT EXISTS ai_jobs_pending_claim_idx
ON ai_jobs (status, priority DESC, scheduled_at DESC, created_at DESC)
WHERE status = 'pending';

View File

@@ -330,7 +330,7 @@ WITH picked AS (
AND scheduled_at <= NOW() AND scheduled_at <= NOW()
AND (cardinality($1::text[]) = 0 OR task_type = ANY($1::text[])) AND (cardinality($1::text[]) = 0 OR task_type = ANY($1::text[]))
AND (cardinality($2::text[]) = 0 OR model_profile = ANY($2::text[])) AND (cardinality($2::text[]) = 0 OR model_profile = ANY($2::text[]))
ORDER BY priority DESC, scheduled_at ASC, created_at ASC ORDER BY priority DESC, scheduled_at DESC, created_at DESC
LIMIT $3 LIMIT $3
FOR UPDATE SKIP LOCKED FOR UPDATE SKIP LOCKED
) )

View File

@@ -0,0 +1,5 @@
DROP INDEX IF EXISTS ai_jobs_pending_claim_idx;
CREATE INDEX IF NOT EXISTS ai_jobs_pending_claim_idx
ON ai_jobs (status, priority DESC, scheduled_at ASC, created_at ASC)
WHERE status = 'pending';

View File

@@ -0,0 +1,5 @@
DROP INDEX IF EXISTS ai_jobs_pending_claim_idx;
CREATE INDEX IF NOT EXISTS ai_jobs_pending_claim_idx
ON ai_jobs (status, priority DESC, scheduled_at DESC, created_at DESC)
WHERE status = 'pending';