From 8d4afaf2298b387cb847d50ed4142964c42f0db9 Mon Sep 17 00:00:00 2001 From: Joshua Pinter Date: Mon, 13 Dec 2021 13:14:21 -0700 Subject: [PATCH] Ignore future jobs in `jobs:check`. If there are scheduled jobs in the future, they should not be included in the `jobs:check`, which is intended to look for jobs that *should* be processed but have not yet been processed. --- lib/delayed/tasks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/delayed/tasks.rb b/lib/delayed/tasks.rb index 409ba48f8..7e80d775f 100644 --- a/lib/delayed/tasks.rb +++ b/lib/delayed/tasks.rb @@ -30,7 +30,7 @@ task :check, [:max_age] => :environment do |_, args| args.with_defaults(:max_age => 300) - unprocessed_jobs = Delayed::Job.where('attempts = 0 AND created_at < ?', Time.now - args[:max_age].to_i).count + unprocessed_jobs = Delayed::Job.where('attempts = 0 AND created_at < ? AND run_at <= ?', Time.now - args[:max_age].to_i, Time.now).count if unprocessed_jobs > 0 raise "#{unprocessed_jobs} jobs older than #{args[:max_age]} seconds have not been processed yet"