Change notificationworker to use a data interface
This commit is contained in:
parent
8ec198228c
commit
b6f1782642
10 changed files with 149 additions and 56 deletions
|
@ -1,29 +1,22 @@
|
|||
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
|
||||
from workers.notificationworker.models_pre_oci import pre_oci_model as model
|
||||
from workers.queueworker import QueueWorker, JobException
|
||||
|
||||
from data import model
|
||||
from data.model import InvalidNotificationException
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NotificationWorker(QueueWorker):
|
||||
def process_queue_item(self, job_details):
|
||||
notification_uuid = job_details['notification_uuid']
|
||||
|
||||
try:
|
||||
notification = model.notification.get_enabled_notification(notification_uuid)
|
||||
except InvalidNotificationException:
|
||||
notification = model.get_enabled_notification(job_details['notification_uuid'])
|
||||
if notification is None:
|
||||
return
|
||||
|
||||
event_name = notification.event.name
|
||||
method_name = notification.method.name
|
||||
event_name = notification.event_name
|
||||
method_name = notification.method_name
|
||||
|
||||
try:
|
||||
event_handler = NotificationEvent.get_event(event_name)
|
||||
|
@ -38,9 +31,9 @@ class NotificationWorker(QueueWorker):
|
|||
if event_handler.should_perform(job_details['event_data'], notification):
|
||||
try:
|
||||
method_handler.perform(notification, event_handler, job_details)
|
||||
reset_number_of_failures_to_zero(notification.id)
|
||||
model.reset_number_of_failures_to_zero(notification)
|
||||
except (JobException, KeyError) as exc:
|
||||
increment_notification_failure_count(notification.id)
|
||||
model.increment_notification_failure_count(notification)
|
||||
raise exc
|
||||
|
||||
|
||||
|
|
Reference in a new issue