Update update_notification_status_by_id DAO function

Replaced `.with_for_lockmode()`, which is now deprecated, with
`.with_for_update() - https://docs.sqlalchemy.org/en/latest/orm/query.html#sqlalchemy.orm.query.Query.with_lockmode

The function should update any statuses that are not 'final', so added
`pending-virus-check` to the list of statuses that the function can
update.
This commit is contained in:
Katie Smith
2018-11-13 14:20:24 +00:00
parent 7ec3dbd667
commit 902e1b403a
2 changed files with 12 additions and 2 deletions

View File

@@ -39,6 +39,7 @@ from app.models import (
NOTIFICATION_DELIVERED,
NOTIFICATION_SENDING,
NOTIFICATION_PENDING,
NOTIFICATION_PENDING_VIRUS_CHECK,
NOTIFICATION_TECHNICAL_FAILURE,
NOTIFICATION_TEMPORARY_FAILURE,
NOTIFICATION_PERMANENT_FAILURE,
@@ -145,13 +146,14 @@ def _update_notification_status(notification, status):
@statsd(namespace="dao")
@transactional
def update_notification_status_by_id(notification_id, status, sent_by=None):
notification = Notification.query.with_lockmode("update").filter(
notification = Notification.query.with_for_update().filter(
Notification.id == notification_id,
or_(
Notification.status == NOTIFICATION_CREATED,
Notification.status == NOTIFICATION_SENDING,
Notification.status == NOTIFICATION_PENDING,
Notification.status == NOTIFICATION_SENT
Notification.status == NOTIFICATION_SENT,
Notification.status == NOTIFICATION_PENDING_VIRUS_CHECK
)).first()
if not notification: