Skip to content

Instantly share code, notes, and snippets.

@joeyAghion
Last active April 8, 2018 02:14
Show Gist options
  • Select an option

  • Save joeyAghion/9274268 to your computer and use it in GitHub Desktop.

Select an option

Save joeyAghion/9274268 to your computer and use it in GitHub Desktop.
delayed jobs by queue and priority
# Number of queued jobs per queue and priority
pp Delayed::Job.distinct(:queue).sort.map{|q| Delayed::Job.where(queue: q).distinct(:priority).sort.map{|p| [q, p, Delayed::Job.where(queue: q, priority: p).count] } }.sort; nil
# First 20 jobs, in order that workers dequeue them
pp Delayed::Job.where(:run_at.lte => Time.now.utc, failed_at: nil).any_of({locked_by: /worker/}, {locked_at: nil}, {locked_at: {'$lt' => (Time.now.utc - 14400)}}).any_in(queue: %w{any imgs}).desc(:locked_by).asc(:priority).asc(:run_at).limit(20).map{|j| [j.id, j.handler.inspect[0..250], j.locked_by, j.run_at, (Time.now.utc - j.locked_at if j.locked_at)] }; nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment