Skip to content

A platform for community discussion. Free, open, simple.

FIX: Handle SMTPServerBusy for group smtp email (#13632)

Martin Brennanb3d3ad250beb
diff --git a/app/jobs/regular/group_smtp_email.rb b/app/jobs/regular/group_smtp_email.rb
index 66eadb9ab6d..ce113e5a77f 100644
--- a/app/jobs/regular/group_smtp_email.rb
+++ b/app/jobs/regular/group_smtp_email.rb
@@ -8,6 +8,19 @@ module Jobs
sidekiq_options queue: 'critical'
+ sidekiq_retry_in do |count, exception|
+ # retry in an hour when SMTP server is busy
+ # or use default sidekiq retry formula. returning
+ # nil/0 will trigger the default sidekiq
+ # retry formula
+ #
+ # See https://github.com/mperham/sidekiq/blob/3330df0ee37cfd3e0cd3ef01e3e66b584b99d488/lib/sidekiq/job_retry.rb#L216-L234
+ case exception.wrapped
+ when Net::SMTPServerBusy
+ return 1.hour + (rand(30) * (count + 1))
+ end
+ end
+
def execute(args)
return if quit_email_early?
diff --git a/app/jobs/regular/notify_mailing_list_subscribers.rb b/app/jobs/regular/notify_mailing_list_subscribers.rb
index 3f71efb3435..861dc27977c 100644
--- a/app/jobs/regular/notify_mailing_list_subscribers.rb
+++ b/app/jobs/regular/notify_mailing_list_subscribers.rb
@@ -12,11 +12,13 @@ module Jobs
sidekiq_options retry: RETRY_TIMES.size
sidekiq_retry_in do |count, exception|
+ # returning nil/0 will trigger the default sidekiq
+ # retry formula
+ #
+ # See https://github.com/mperham/sidekiq/blob/3330df0ee37cfd3e0cd3ef01e3e66b584b99d488/lib/sidekiq/job_retry.rb#L216-L234
case exception.wrapped
when SocketError
- RETRY_TIMES[count]
- else
- ::Jobs::UserEmail.seconds_to_delay(count)
+ return RETRY_TIMES[count]
end
end
diff --git a/app/jobs/regular/user_email.rb b/app/jobs/regular/user_email.rb
index df53f471fd3..d63d17ea4ca 100644
--- a/app/jobs/regular/user_email.rb
+++ b/app/jobs/regular/user_email.rb
@@ -8,6 +8,19 @@ module Jobs
sidekiq_options queue: 'low'
+ sidekiq_retry_in do |count, exception|
+ # retry in an hour when SMTP server is busy
+ # or use default sidekiq retry formula. returning
+ # nil/0 will trigger the default sidekiq
+ # retry formula
+ #
+ # See https://github.com/mperham/sidekiq/blob/3330df0ee37cfd3e0cd3ef01e3e66b584b99d488/lib/sidekiq/job_retry.rb#L216-L234
+ case exception.wrapped
+ when Net::SMTPServerBusy
+ return 1.hour + (rand(30) * (count + 1))
+ end
+ end
+
# Can be overridden by subclass, for example critical email
# should always consider being sent
def quit_email_early?
@@ -206,22 +219,6 @@ 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)