3 ms·
> With that in place you could acquire events from the queue like so: UPDATE event_queue SET acquired_at = now() WHERE id IN ( SELECT id FROM event_q
by reese_john 3y ago
> With that in place you could acquire events from the queue like so:
UPDATE event_queue
SET acquired_at = now()
WHERE id IN (
SELECT id
FROM event_queue
WHERE acquired_at IS NULL
ORDER BY occurred_at
LIMIT 1000 -- Set this limit according to your usage
)
RETURNING *;
Would you need a FOR UPDATE in that subquery?
- Mavvie 3y agoNo, because they're setting acquired_at which marks it as "handled". You only need FOR UPDATE (SKIP LOCKED) if you want to process the event inside a transaction; but the approach in the article is to just bulk "grab the events and mark them as done, atomically"