Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to exclude locked jobs (i.e. currently being processed) in jobs:check. #1087

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 < ? AND run_at <= ?', Time.now - args[:max_age].to_i, Time.now)
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"
Expand Down