FIX: retry sending an email in 1 hour when SMTP server is busy

This commit is contained in:
Régis Hanol 2016-05-09 20:37:33 +02:00
parent e8623ccd92
commit d224966a0e
3 changed files with 20 additions and 5 deletions

View File

@ -173,10 +173,9 @@ module Jobs
if exceptions.length > 0
exceptions.each do |exception_hash|
Discourse.handle_job_exception(exception_hash[:ex],
error_context(opts, exception_hash[:code], exception_hash[:other]))
Discourse.handle_job_exception(exception_hash[:ex], error_context(opts, exception_hash[:code], exception_hash[:other]))
end
raise HandledExceptionWrapper.new exceptions[0][:ex]
raise HandledExceptionWrapper.new(exceptions[0][:ex])
end
nil

View File

@ -150,6 +150,22 @@ module Jobs
[message, nil]
end
sidekiq_retry_in do |count, exception|
# retry in an hour when SMTP server is busy
# or use default sidekiq retry formula
case exception.wrapped
when Net::SMTPServerBusy
1.hour + (rand(30) * (count + 1))
else
Jobs::UserEmail.seconds_to_delay(count)
end
end
# extracted from sidekiq
def self.seconds_to_delay(count)
(count ** 4) + 15 + (rand(30) * (count + 1))
end
private
def skip_message(reason)

View File

@ -135,8 +135,8 @@ module Email
# Suppress images from short emails
if SiteSetting.strip_images_from_short_emails &&
@message.html_part.body.to_s.bytesize <= SiteSetting.short_email_length &&
@message.html_part.body =~ /<img[^>]+>/
@message.html_part.body.to_s.bytesize <= SiteSetting.short_email_length &&
@message.html_part.body =~ /<img[^>]+>/
style = Email::Styles.new(@message.html_part.body.to_s)
@message.html_part.body = style.strip_avatars_and_emojis
end