Created
December 5, 2024 14:24
-
-
Save ismasan/07dcd892da7b9206c9cdead49f52eacd to your computer and use it in GitHub Desktop.
Postgres-based job queue using FOR UPDATE SKIP LOCKED
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH next_job AS ( | |
SELECT | |
id, | |
type, | |
payload, | |
created_at | |
FROM jobs | |
WHERE created_at <= ? | |
ORDER BY created_at | |
FOR UPDATE SKIP LOCKED | |
LIMIT 1 | |
) | |
DELETE FROM jobs | |
WHERE id IN (SELECT id FROM next_job) | |
RETURNING *; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment