From 779d4e7287695c97dc2a04cd0dbf423fc7396b9b Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 31 Mar 2023 17:43:13 +0000 Subject: [PATCH] Process queued background jobs before re-trying stalled --- CHANGELOG.md | 4 ++++ mitra-models/src/background_jobs/queries.rs | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bca1981..02d5e13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Limit number of mentions and links in remote posts. +### Fixed + +- Process queued background jobs before re-trying stalled. + ## [1.19.0] - 2023-03-30 ### Added diff --git a/mitra-models/src/background_jobs/queries.rs b/mitra-models/src/background_jobs/queries.rs index cedca1b..2594134 100644 --- a/mitra-models/src/background_jobs/queries.rs +++ b/mitra-models/src/background_jobs/queries.rs @@ -48,11 +48,16 @@ pub async fn get_job_batch( job_type = $2 AND scheduled_for < CURRENT_TIMESTAMP AND ( - job_status = $3 --queued - OR job_status = $1 --running + -- queued + job_status = $3 + -- running + OR job_status = $1 AND updated_at < CURRENT_TIMESTAMP - $5::text::interval ) - ORDER BY scheduled_for ASC + ORDER BY + -- queued jobs first + job_status ASC, + scheduled_for ASC LIMIT $4 ) RETURNING background_job