Skip to content

Commit

Permalink
Send emails to celery after committing
Browse files Browse the repository at this point in the history
In case the celery broker (redis) is down this may result in lost
emails, but this is a very unlikely case (especially since usually
sessions wouldn't work either with redis being down) and without
committing first, an event log entry may not be persisted in the
database yet when the task runs and wants to update its state.
  • Loading branch information
ThiefMaster committed Oct 25, 2017
1 parent 3504666 commit a88ae8f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
5 changes: 0 additions & 5 deletions indico/core/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ def _log_email(email, event, module, user):
user, type_='email', data=log_data)


def has_email_queue():
"""Check whether there are any emails queued"""
return bool(g.get('email_queue'))


def flush_email_queue():
"""Send all the emails in the queue"""
queue = g.pop('email_queue', [])
Expand Down
9 changes: 2 additions & 7 deletions indico/web/rh.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from indico.core.db import db
from indico.core.db.sqlalchemy.core import handle_sqlalchemy_database_error
from indico.core.logger import Logger, sentry_set_tags
from indico.core.notifications import flush_email_queue, has_email_queue
from indico.core.notifications import flush_email_queue
from indico.legacy.common import fossilize
from indico.legacy.common.security import Sanitization
from indico.util.i18n import _
Expand Down Expand Up @@ -270,13 +270,8 @@ def process(self):
signals.after_process.send()

if self.commit:
if has_email_queue():
# ensure we fail early (before sending out e-mails)
# in case there are DB constraint violations, etc...
db.enforce_constraints()
flush_email_queue()

db.session.commit()
flush_email_queue()
else:
db.session.rollback()
except DatabaseError:
Expand Down

0 comments on commit a88ae8f

Please sign in to comment.