Prioritize newest AI jobs
This commit is contained in:
5
internal/migrate/sql/003_ai_jobs_newest_first.up.sql
Normal file
5
internal/migrate/sql/003_ai_jobs_newest_first.up.sql
Normal 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';
|
||||
@@ -330,7 +330,7 @@ WITH picked AS (
|
||||
AND scheduled_at <= NOW()
|
||||
AND (cardinality($1::text[]) = 0 OR task_type = ANY($1::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
|
||||
FOR UPDATE SKIP LOCKED
|
||||
)
|
||||
|
||||
5
migrations/003_ai_jobs_newest_first.down.sql
Normal file
5
migrations/003_ai_jobs_newest_first.down.sql
Normal 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';
|
||||
5
migrations/003_ai_jobs_newest_first.up.sql
Normal file
5
migrations/003_ai_jobs_newest_first.up.sql
Normal 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';
|
||||
Reference in New Issue
Block a user