diff --git a/lib/delayed/tasks.rb b/lib/delayed/tasks.rb index 409ba48f8..dd8f14899 100644 --- a/lib/delayed/tasks.rb +++ b/lib/delayed/tasks.rb @@ -27,10 +27,12 @@ end desc "Exit with error status if any jobs older than max_age seconds haven't been attempted yet." - task :check, [:max_age] => :environment do |_, args| - args.with_defaults(:max_age => 300) + task :check, [:max_age, :not_locked] => :environment do |_, args| + args.with_defaults(:max_age => 300, :not_locked => false) - 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 < ?', Time.now - args[:max_age].to_i) + unprocessed_jobs = unprocessed_jobs.where('locked_at IS NULL') if args[:not_locked] + unprocessed_jobs = unprocessed_jobs.count if unprocessed_jobs > 0 raise "#{unprocessed_jobs} jobs older than #{args[:max_age]} seconds have not been processed yet"