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_failure.map { |key, exs| [key, exs.size] }]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment