Skip to content

Commit

Permalink
Merge af2be48 into 460018e
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuapinter committed May 9, 2019
2 parents 460018e + af2be48 commit 9b85fd3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/delayed/tasks.rb
Expand Up @@ -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('AND 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"
Expand Down

0 comments on commit 9b85fd3

Please sign in to comment.