Skip to content
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

Fix sentry-delayed_job: respect custom max_attempts #2177

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion sentry-delayed_job/lib/sentry/delayed_job/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def self.report?(job)

# We use the predecessor because the job's attempts haven't been increased to the new
# count at this point.
job.attempts >= Delayed::Worker.max_attempts.pred
max_attempts = job&.max_attempts&.pred || Delayed::Worker.max_attempts.pred
job.attempts >= max_attempts
end

def self.finish_transaction(transaction, status)
Expand Down
16 changes: 16 additions & 0 deletions sentry-delayed_job/spec/sentry/delayed_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ def self.class_do_nothing
expect(transport.events.count).to eq(1)
end

# Default max_attemps is defined on Delayed::Worker.max_attempts == 25.
# However, users can customize max_attempts on the job class, and DelayedJob
# will respect that.
# Sentry needs to report an exception if report_after_retries is true and
# custom job-level max_attempts is reached.
# See https://github.com/collectiveidea/delayed_job#custom-jobs
it "reports exception after the job's custom max_attempts" do
enqueued_job.update(attempts:2)
natikgadzhi marked this conversation as resolved.
Show resolved Hide resolved
allow(enqueued_job).to receive(:max_attempts).and_return(3)

expect do
enqueued_job.invoke_job
end.to raise_error(ZeroDivisionError)
expect(transport.events.count).to eq(1)
end

it "skips report if not on the last retry" do
enqueued_job.update(attempts: 0)

Expand Down
Loading