Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mahemoff
Created June 12, 2017 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahemoff/af1ca4bcdf912f89e65e88cc874cce01 to your computer and use it in GitHub Desktop.
Save mahemoff/af1ca4bcdf912f89e65e88cc874cce01 to your computer and use it in GitHub Desktop.
Sidekiq Utils for make simplify your debugging
Class SidekiqUtils
def self.queues
::Sidekiq::Stats.new.queues.keys.map { |name| ::Sidekiq::Queue.new(name) }
end
def self.find_queue(name)
self.queues.find { |q| q.name==name.to_s }
end
def self.jobs
queue = self.find_queue(queue) if !queue.is_a?(Sidekiq::Queue)
return [] if !queue
the_jobs = []
queue.each { |job| the_jobs << job }
the_jobs
end
# generate string with all queues
def self.all
header_string = "All queues (#{self.queues.size})"
queue_strings = self.queues.map { |q|
queue_header_string = "#{q.name} (#{self.jobs(q).size} jobs):"
jobs_string = self.jobs(q).map { |job|
"#{job['class']} #{job.args}"
}.join("\n")
"----\n#{queue_header_string}\n#{jobs_string}"
}
"#{header_string}\n#{queue_strings.join("\n")}"
end
end
puts SidekiqUtils.all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment