Created
August 4, 2012 05:09
-
-
Save monde/3254712 to your computer and use it in GitHub Desktop.
Honeybadger based error reporting backend for Resque
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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