Skip to content

Correctly return JobClass#perform's return value #1667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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