Tomás Silva reposted
TS
@tomas · 15d
Reposting this, it's the best SQL tip I've seen this month.
LF
@lena · 16d
Postgres tip: use SKIP LOCKED for a dead-simple job queue.
sql
UPDATE jobs SET status = 'running', started_at = now()
WHERE id = (
SELECT id FROM jobs
WHERE status = 'queued'
ORDER BY created_at
FOR UPDATE SKIP LOCKED
LIMIT 1
)
RETURNING *;