Skip to content

Instantly share code, notes, and snippets.

@monde
Created August 4, 2012 05:09
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save monde/3254712 to your computer and use it in GitHub Desktop.
Honeybadger based error reporting backend for Resque
# for Rails place in config/initializers/honeybadger_resque.rb
%w( resque honeybadger ).each do |gem|
begin
require gem
rescue LoadError
raise "Can't find '#{gem}' gem. Please add it to your Gemfile or install it."
end
end
module Resque
module Failure
# A Failure backend that sends exceptions raised by jobs to Honeybadger.
#
# To use it, put this code in an initializer, Rake task, or wherever:
#
# Resque::Failure::Multiple.classes = [Resque::Failure::Redis, Resque::Failure::Honeybadger]
# Resque::Failure.backend = Resque::Failure::Multiple
#
# Once you've configured resque to use the Honeybadger failure backend,
# you'll want to setup an initializer to configure the Honeybadger.
#
# Honeybadger.configure do |config|
# config.api_key = 'your_key_here'
# end
class Honeybadger < Base
def configure(&block)
Resque::Failure.backend = self
::Honeybadger.configure(&block)
end
def count
# We can't get the total # of errors from Hoptoad so we fake it
# by asking Resque how many errors it has seen.
Stat[:failed]
end
def save
::Honeybadger.notify_or_ignore(exception,
:parameters => {
:payload_class => payload['class'].to_s,
:payload_args => payload['args'].inspect
}
)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment