Skip to content

Instantly share code, notes, and snippets.

@jeffrafter
Created August 14, 2014 00:16
Show Gist options
  • Save jeffrafter/7bde2c9dada1b93e6c19 to your computer and use it in GitHub Desktop.
Save jeffrafter/7bde2c9dada1b93e6c19 to your computer and use it in GitHub Desktop.
Want to inspect your Sidekiq queues?
def fetch_contents(queue = "default", max = 100000)
Sidekiq.redis do |r|
r.lrange("queue:#{queue}", 0, max)
end;
end
def sidekiq_job_breakdown(queue = "default", contents = nil)
re = /\"class":"([0-9A-Za-z_::]+)"/
contents ||= fetch_contents(queue)
counts = contents.inject(Hash.new(0)) do |h, e|
begin
key = e.match(re)[1]
rescue
# If you get a result set for "nil" then
# the regex above is not finding the class
# This could get noisy if you turn it on
# puts "in redis: #{e}"
end
h[key] += 1 ; h
end
counts
end
def first_job_index(re, queue = "default", contents = nil)
contents ||= fetch_contents(queue)
jobs = contents.select do |job|
job =~ re
end
return nil if jobs.empty?
contents.index(jobs[0])
end
contents = fetch_contents; nil # Don't spew to the console
first_job_index(/some unique pattern goes here/, "default", contents)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment