feat(worker): claim_next skips per-item paused jobs
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,7 +30,7 @@ def claim_next(conn: psycopg.Connection) -> str | None:
|
||||
cur.execute(
|
||||
"""
|
||||
SELECT id FROM "Job"
|
||||
WHERE state = 'requested'
|
||||
WHERE state = 'requested' AND NOT paused
|
||||
ORDER BY "createdAt" ASC
|
||||
FOR UPDATE SKIP LOCKED
|
||||
LIMIT 1
|
||||
|
||||
@@ -24,3 +24,17 @@ def test_claim_does_not_repick_claimed_job(conn):
|
||||
insert_request(conn)
|
||||
assert claim_next(conn) is not None
|
||||
assert claim_next(conn) is None
|
||||
|
||||
|
||||
def test_claim_skips_paused_jobs(conn):
|
||||
paused_job = insert_request(conn, album="Paused Album")
|
||||
with conn.cursor() as cur:
|
||||
cur.execute('UPDATE "Job" SET paused = true WHERE id = %s', (paused_job,))
|
||||
conn.commit()
|
||||
unpaused_job = insert_request(conn, album="Live Album")
|
||||
|
||||
claimed = claim_next(conn)
|
||||
assert claimed == unpaused_job # the paused one is skipped
|
||||
|
||||
# With only the paused job left, nothing is claimable.
|
||||
assert claim_next(conn) is None
|
||||
|
||||
Reference in New Issue
Block a user