mirror of
https://github.com/sartography/uva-covid19-testing-communicator.git
synced 2025-02-23 12:28:26 +00:00
Trying to catch the too many messages error, and just stop rather than failing on all subsequent samples, so that it just keeps trying.
This commit is contained in:
parent
2396d2442f
commit
b2449c4d89
@ -1,3 +1,5 @@
|
||||
import smtplib
|
||||
|
||||
from communicator import db, app, executor
|
||||
from communicator.models import Sample
|
||||
from communicator.models.invitation import Invitation
|
||||
@ -87,12 +89,27 @@ def _notify_by_email(file_name=None, retry=False):
|
||||
count += 1
|
||||
sample.email_notified = True
|
||||
db.session.add(Notification(type=EMAIL_TYPE, sample=sample, successful=True))
|
||||
except smtplib.SMTPServerDisconnected as de:
|
||||
app.logger.error("Database connection terminated, stopping for now.", exc_info=True)
|
||||
break
|
||||
except smtplib.SMTPResponseException as re:
|
||||
if re.smtp_code == 451:
|
||||
app.logger.error("Too many messages error from SMTP Service, stopping for now.", exc_info=True)
|
||||
break
|
||||
else:
|
||||
app.logger.error(f'An exception happened in EmailService sending to {sample.email} ', exc_info=True)
|
||||
app.logger.error(str(e))
|
||||
db.session.add(Notification(type=EMAIL_TYPE, sample=sample, successful=False,
|
||||
error_message=str(e)))
|
||||
except Exception as e:
|
||||
app.logger.error(f'An exception happened in EmailService sending to {sample.email} ', exc_info=True)
|
||||
app.logger.error(str(e))
|
||||
db.session.add(Notification(type=EMAIL_TYPE, sample=sample, successful=False,
|
||||
error_message=str(e)))
|
||||
db.session.commit()
|
||||
sleep(0.5)
|
||||
if count > 190:
|
||||
if count > 190: # At 2 a second, it should take 80 seconds or around a minute and 1/2 to send out a set.
|
||||
app.logger.info("Reached the max 190 messages, stopping for now.")
|
||||
break
|
||||
|
||||
|
||||
|
@ -182,13 +182,7 @@ class NotificationService(object):
|
||||
return
|
||||
|
||||
all_recipients = recipients + bcc
|
||||
|
||||
try:
|
||||
self.email_server.sendmail(sender, all_recipients, msgRoot.as_bytes())
|
||||
except Exception as e:
|
||||
app.logger.error('An exception happened in EmailService', exc_info=True)
|
||||
app.logger.error(str(e))
|
||||
raise CommError(5000, f"failed to send email to {', '.join(recipients)}", e)
|
||||
self.email_server.sendmail(sender, all_recipients, msgRoot.as_bytes())
|
||||
|
||||
def is_reasonable_hour_for_text_messages(self):
|
||||
"""Where 'reasaonable' is between 8am and 10pm. """
|
||||
|
Loading…
x
Reference in New Issue
Block a user