add retry mechanism when sending email to new user
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
fa05c4ad4a
commit
41d293ee3b
|
@ -1,3 +1,5 @@
|
||||||
|
import smtplib
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from typing import Union, List
|
from typing import Union, List
|
||||||
|
|
||||||
|
@ -89,12 +91,25 @@ class AddMemberTransaction(AbstractTransaction):
|
||||||
# The following operations can't/shouldn't be rolled back because the
|
# The following operations can't/shouldn't be rolled back because the
|
||||||
# user has already seen the email
|
# user has already seen the email
|
||||||
|
|
||||||
|
# sometimes Postfix says 'User unknown in local recipient table' if we try
|
||||||
|
# to send an email to a user right after they were created
|
||||||
|
max_tries = 3
|
||||||
|
for i in range(max_tries):
|
||||||
try:
|
try:
|
||||||
self.mail_srv.send_welcome_message_to(user, password)
|
self.mail_srv.send_welcome_message_to(user, password)
|
||||||
yield 'send_welcome_message'
|
yield 'send_welcome_message'
|
||||||
|
break
|
||||||
|
except smtplib.SMTPRecipientsRefused:
|
||||||
|
if i < max_tries - 1:
|
||||||
|
logger.warning('SMTP recipient refused, sleeping and trying again')
|
||||||
|
time.sleep(3)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
yield 'failed_to_send_welcome_message: recipient refused too many times'
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
logger.warning('send_welcome_message failed:\n' + traceback.format_exc())
|
logger.warning('send_welcome_message failed:\n' + traceback.format_exc())
|
||||||
yield 'failed_to_send_welcome_message: ' + str(err)
|
yield 'failed_to_send_welcome_message: ' + str(err)
|
||||||
|
break
|
||||||
|
|
||||||
# don't subscribe club reps to csc-general
|
# don't subscribe club reps to csc-general
|
||||||
if self.terms:
|
if self.terms:
|
||||||
|
|
Loading…
Reference in New Issue