Skip to content

Commit

Permalink
Make sure that calls to Airbrake.notify are always synchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
joaodiogocosta committed Oct 6, 2017
1 parent 529eb24 commit 78a112c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 17 additions & 6 deletions lib/resque/failure/airbrake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ def self.count(queue = nil, class_name = nil)
end

def save
::Airbrake.notify(exception,
:parameters => {
:payload_class => payload['class'].to_s,
:payload_args => payload['args'].inspect
}
)
notify(exception,
:parameters => {
:payload_class => payload['class'].to_s,
:payload_args => payload['args'].inspect
}
)
end

private

def notify(exception, options)
if ::Airbrake.respond_to?(:notify_sync)
Airbrake.notify_sync(exception, options)
else
# Older versions of Airbrake (< 5)
Airbrake.notify(exception, options)
end
end
end
end
Expand Down
9 changes: 8 additions & 1 deletion test/airbrake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@
queue = "test"
payload = {'class' => Object, 'args' => 66}

Airbrake.expects(:notify).with(
notify_method =
if Airbrake::AIRBRAKE_VERSION.to_i < 5
:notify
else
:notify_sync
end

Airbrake.expects(notify_method).with(
exception,
:parameters => {:payload_class => 'Object', :payload_args => '66'})

Expand Down

0 comments on commit 78a112c

Please sign in to comment.