feat(full-stack): disable notifications after 3 failures

This stops notifications from firing over and over again if they are repeatedly failing.

[TESTING -> locally with docker compose, DATABASE MIGRATION -> there is a single migration]

Issue: https://www.pivotaltracker.com/story/show/b144646649n

- [ ] It works!
- [ ] Comments provide sufficient explanations for the next contributor
- [ ] Tests cover changes and corner cases
- [ ] Follows Quay syntax patterns and format
This commit is contained in:
Charlton Austin 2017-05-18 17:52:50 -04:00
parent 2282af2619
commit 993f2a174c
13 changed files with 140 additions and 20 deletions

View file

@ -1,6 +1,5 @@
import logging
from app import notification_queue
from data.model.notification import increment_notification_failure_count, reset_number_of_failures_to_zero
from endpoints.notificationmethod import NotificationMethod, InvalidNotificationMethodException
from endpoints.notificationevent import NotificationEvent, InvalidNotificationEventException
@ -9,7 +8,7 @@ from workers.queueworker import QueueWorker, JobException
from data import model
from data.model import InvalidNotificationException
logger = logging.getLogger(__name__)
class NotificationWorker(QueueWorker):
@ -17,9 +16,8 @@ class NotificationWorker(QueueWorker):
notification_uuid = job_details['notification_uuid']
try:
notification = model.notification.get_repo_notification(notification_uuid)
notification = model.notification.get_enabled_notification(notification_uuid)
except InvalidNotificationException:
# Probably deleted.
return
event_name = notification.event.name
@ -36,7 +34,12 @@ class NotificationWorker(QueueWorker):
raise JobException('Cannot find notification event: %s' % ex.message)
if event_handler.should_perform(job_details['event_data'], notification):
method_handler.perform(notification, event_handler, job_details)
try:
method_handler.perform(notification, event_handler, job_details)
reset_number_of_failures_to_zero(notification.id)
except (NotificationMethod, KeyError) as exc:
increment_notification_failure_count(notification.id)
raise exc
if __name__ == "__main__":