Skip to content

Commit

Permalink
Correctly return Job#perform's return value (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
st0012 authored Jan 5, 2022
1 parent 6be24ce commit 1c62438
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sentry-rails/lib/sentry/rails/active_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ def capture_and_reraise_with_sentry(scope, &block)

scope.set_span(transaction) if transaction

block.call
return_value = block.call

finish_sentry_transaction(transaction, 200)

return_value
rescue Exception => e # rubocop:disable Lint/RescueException
finish_sentry_transaction(transaction, 500)

Expand Down
14 changes: 14 additions & 0 deletions sentry-rails/spec/sentry/rails/activejob_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
require "spec_helper"
require "active_job/railtie"

class NormalJob < ActiveJob::Base
def perform
"foo"
end
end

class FailedJob < ActiveJob::Base
self.logger = nil

Expand Down Expand Up @@ -47,6 +53,10 @@ def rescue_callback(error)
it "runs job" do
expect { FailedJob.perform_now }.to raise_error(FailedJob::TestError)
end

it "returns #perform method's return value" do
expect(NormalJob.perform_now).to eq("foo")
end
end

RSpec.describe "ActiveJob integration" do
Expand All @@ -62,6 +72,10 @@ def rescue_callback(error)
Sentry.get_current_client.transport
end

it "returns #perform method's return value" do
expect(NormalJob.perform_now).to eq("foo")
end

it "adds useful context to extra" do
expect { FailedJob.perform_now }.to raise_error(FailedJob::TestError)

Expand Down

0 comments on commit 1c62438

Please sign in to comment.