discourse/lib/sidekiq/suppress_user_email_errors.rb
Gary Pendergast c7e105d15c
FIX: Ensure retry_count is set when checking if a job is being retried (#36034)
When checking how many times an email job has been retried, we need to check
that the `retry_count` attribute has been set.

In a related error, the `UserEmail` retry wait handler assumed that the
triggering exception would always have a `wrapped` attribute, which
isn't necessarily the case if the exception was raised outside of the
job execution code.
2025-11-14 14:18:50 +11:00

16 lines
418 B
Ruby

# frozen_string_literal: true
module Sidekiq
class SuppressUserEmailErrors
def call(worker, job, queue)
yield
rescue => e
# Only suppress email errors from Jobs::UserEmail, and only for the first 3 retries
if worker.class == Jobs::UserEmail && !job["retry_count"].nil? && job["retry_count"] < 3
raise Jobs::HandledExceptionWrapper.new(e)
end
raise e
end
end
end