Adds a retry_timer parameter to the dequeue method. If specified, this selects jobs that have been in 'picked' status for longer than the specified duration. If None, the retry timer job checking is skipped.
The performance of the new query plan is on par with the current implementation, with a slight improvement of a few percentage points. The plan efficiently handles the selection and update of jobs from the queue with minimal overhead and optimized buffer usage.
analyze (verbose) pgqueuer;
explain (analyze, buffers)
WITH next_job_queued AS (
SELECT id
FROM pgqueuer
WHERE status = 'queued'
ORDER BY priority DESC, id ASC
FOR UPDATE SKIP LOCKED
LIMIT 10
),
next_job_timeout AS (
SELECT id
FROM pgqueuer
WHERE status = 'picked' and updated < NOW() - INTERVAL '30 seconds'
ORDER BY id ASC
FOR UPDATE SKIP LOCKED
LIMIT 10
),
combined_jobs AS (
SELECT DISTINCT id
FROM (
SELECT id FROM next_job_queued
UNION ALL
SELECT id FROM next_job_timeout
) AS combined
),
updated AS (
UPDATE pgqueuer
SET status = 'picked', updated = NOW()
WHERE id = ANY(SELECT id FROM combined_jobs)
RETURNING *
)
SELECT * FROM updated ORDER BY priority DESC, id ASC
Adds a
retry_timer
parameter to thedequeue
method. If specified, this selects jobs that have been in 'picked' status for longer than the specified duration. IfNone
, the retry timer job checking is skipped.The performance of the new query plan is on par with the current implementation, with a slight improvement of a few percentage points. The plan efficiently handles the selection and update of jobs from the queue with minimal overhead and optimized buffer usage.