Skip to content

Instantly share code, notes, and snippets.

@Koronen
Last active August 29, 2015 13:57
Show Gist options
  • Save Koronen/9738152 to your computer and use it in GitHub Desktop.
Save Koronen/9738152 to your computer and use it in GitHub Desktop.
Resque statistics hacks
def failures_with_ids(n)
Resque::Failure.all(0,n).each_with_index.map { |ex, i| ex['id'] = i; ex }
end
def group_by_exception(failures)
failures.reduce({}) do |acc, ex|
acc[ex['exception']] ||= []
acc[ex['exception']] << ex
acc
end
end
def group_by_class(failures)
failures.reduce({}) do |acc, ex|
acc[ex['payload']['class']] ||= []
acc[ex['payload']['class']] << ex
acc
end
end
def value_counts(grouped_failures)
Hash[grouped_failures.map { |key, exs| [key, exs.size] }]
end
failures = Resque::Failure.all(0,9999).each_with_index.map { |ex, i| ex['id'] = i; ex }; nil
fbe = Hash.new { |h, k| h[k] = Array.new }
fbc = Hash.new { |h, k| h[k] = Array.new }
failures.each { |ex| fbe[ex['exception']] << ex; fbc[ex['payload']['class']] << ex }; nil
puts fbe.map { |e,jj| [e, jj.size] }.inspect
puts fbc.map { |e,jj| [e, jj.size] }.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment