forked from resque/resque
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds Airbrake support while continuing backwards compatibility for Ho…
…ptoad. Adds tests for Airbrake.
- Loading branch information
1 parent
9beb796
commit 2113127
Showing
5 changed files
with
82 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
begin | ||
require 'airbrake' | ||
rescue LoadError | ||
raise "Can't find 'airbrake' gem. Please add it to your Gemfile or install it." | ||
end | ||
|
||
require 'resque/failure/thoughtbot' | ||
|
||
module Resque | ||
module Failure | ||
class Airbrake < Base | ||
include Resque::Failure::Thoughtbot | ||
|
||
@klass = ::Airbrake | ||
end | ||
end | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Resque | ||
module Failure | ||
module Thoughtbot | ||
def self.included(base) | ||
base.extend(ClassMethods) | ||
end | ||
|
||
module ClassMethods | ||
attr_accessor :klass | ||
|
||
def configure(&block) | ||
Resque::Failure.backend = self | ||
klass.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 | ||
end | ||
|
||
def save | ||
self.class.klass.notify_or_ignore(exception, | ||
:parameters => { | ||
:payload_class => payload['class'].to_s, | ||
:payload_args => payload['args'].inspect | ||
} | ||
) | ||
end | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
require 'test_helper' | ||
|
||
begin | ||
require 'airbrake' | ||
rescue LoadError | ||
warn "Install airbrake gem to run Airbrake tests." | ||
end | ||
|
||
if defined? Airbrake | ||
require 'resque/failure/airbrake' | ||
context "Airbrake" do | ||
test "should be notified of an error" do | ||
exception = StandardError.new("BOOM") | ||
worker = Resque::Worker.new(:test) | ||
queue = "test" | ||
payload = {'class' => Object, 'args' => 66} | ||
|
||
Airbrake.expects(:notify_or_ignore).with( | ||
exception, | ||
:parameters => {:payload_class => 'Object', :payload_args => '66'}) | ||
|
||
backend = Resque::Failure::Airbrake.new(exception, worker, queue, payload) | ||
backend.save | ||
end | ||
end | ||
end |
This file contains 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