Skip to content

Instantly share code, notes, and snippets.

@christopher-b
Last active December 20, 2015 00:08
Show Gist options
  • Save christopher-b/6038992 to your computer and use it in GitHub Desktop.
Save christopher-b/6038992 to your computer and use it in GitHub Desktop.
Canvas LMS rake task to return the number of queued delayed jobs
namespace :ocadu do
"Returns the number of delayed jobs in the queue"
task :job_count => :environment do
puts Delayed::Job.where("run_at < UTC_TIMESTAMP() AND locked_at is null").count
end
end
@codekitchen
Copy link

Note that this will include the count of currently running jobs and jobs scheduled in the future as well, which could throw off your monitoring if there are a significant number of them. Here @ Instructure we use this SQL query to monitor the job queue size:

select count(1) from delayed_jobs where run_at < now() and locked_at is null;

@christopher-b
Copy link
Author

Thanks Brian!

@christopher-b
Copy link
Author

BTW, I think for MySQL the query should be:

select count(1) from delayed_jobs where run_at < UTC_TIMESTAMP() and locked_at is null;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment