Skip to content

Commit

Permalink
Add jobs:check rake task to test for liveness.
Browse files Browse the repository at this point in the history
This task exits with failure status if there are old jobs that have
not been picked up by workers. This can be used for monitoring.
  • Loading branch information
mmb committed May 5, 2013
1 parent fe0fa6c commit 44c680e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/delayed/tasks.rb
Expand Up @@ -22,4 +22,17 @@
:quiet => false
}
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)

unprocessed_jobs = Delayed::Job.where('attempts = 0 AND created_at < ?', Time.now - args[:max_age].to_i).count

if unprocessed_jobs > 0
fail "#{unprocessed_jobs} jobs older than #{args[:max_age]} seconds have not been processed yet"
end

end

end

0 comments on commit 44c680e

Please sign in to comment.