diff --git a/worker/lyra_worker/claim.py b/worker/lyra_worker/claim.py index 10e21f6..788d128 100644 --- a/worker/lyra_worker/claim.py +++ b/worker/lyra_worker/claim.py @@ -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 diff --git a/worker/tests/test_claim.py b/worker/tests/test_claim.py index 4620247..ab05f9d 100644 --- a/worker/tests/test_claim.py +++ b/worker/tests/test_claim.py @@ -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