Last active
December 20, 2015 00:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Thanks Brian!
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
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: