Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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