Downgrade log level for missing notifications in SES receipt

The timestamps available in the SES receipt don't always correspond
to the time the notification has been sent. We've seen callbacks with
a current timestamp in both 'mail' and 'bounce' objects that referenced
a notification sent a week ago, which means we can't rely on it to skip
archived notifications.

One possible approach would be to look up the notification reference in
the notification_history table, but this goes against our plans to stop
relying on it in the future.

This changes the SES receipts logic to retry missing notifications once
(if the callback timestamp is within the last 5 minutes the task will
retry after a 5 minute delay) to capture callbacks arriving before the
notification reference has been persisted to the DB. Otherwise, we log
the missing notification as a warning instead of error.
This commit is contained in:
Alexey Bezhan
2019-03-06 11:35:32 +00:00
parent a355a98442
commit 6f5822ae5b
2 changed files with 4 additions and 4 deletions

View File

@@ -42,10 +42,10 @@ def process_ses_results(self, response):
notification = notifications_dao.dao_get_notification_by_reference(reference)
except NoResultFound:
message_time = iso8601.parse_date(ses_message['mail']['timestamp']).replace(tzinfo=None)
if datetime.utcnow() - message_time < timedelta(minutes=10):
if datetime.utcnow() - message_time < timedelta(minutes=5):
self.retry(queue=QueueNames.RETRY)
elif datetime.utcnow() - message_time < timedelta(days=3):
current_app.logger.error(
else:
current_app.logger.warning(
"notification not found for reference: {} (update to {})".format(reference, notification_status)
)
return