2014-07-18 02:51:58 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from app import notification_queue
|
|
|
|
|
|
|
|
from endpoints.notificationmethod import NotificationMethod, InvalidNotificationMethodException
|
|
|
|
from endpoints.notificationevent import NotificationEvent, InvalidNotificationEventException
|
2015-07-28 21:25:12 +00:00
|
|
|
from workers.queueworker import QueueWorker, JobException
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
from data import model
|
2015-08-17 21:54:33 +00:00
|
|
|
from data.model import InvalidNotificationException
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-07-28 21:25:12 +00:00
|
|
|
class NotificationWorker(QueueWorker):
|
2014-07-18 02:51:58 +00:00
|
|
|
def process_queue_item(self, job_details):
|
2015-07-15 21:25:41 +00:00
|
|
|
notification_uuid = job_details['notification_uuid']
|
2014-11-24 21:07:38 +00:00
|
|
|
|
2015-08-14 19:42:31 +00:00
|
|
|
try:
|
|
|
|
notification = model.notification.get_repo_notification(notification_uuid)
|
2015-08-17 21:54:33 +00:00
|
|
|
except InvalidNotificationException:
|
2014-07-18 02:51:58 +00:00
|
|
|
# Probably deleted.
|
2014-09-22 16:52:57 +00:00
|
|
|
return
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
event_name = notification.event.name
|
|
|
|
method_name = notification.method.name
|
|
|
|
|
|
|
|
try:
|
|
|
|
event_handler = NotificationEvent.get_event(event_name)
|
|
|
|
method_handler = NotificationMethod.get_method(method_name)
|
|
|
|
except InvalidNotificationMethodException as ex:
|
2015-07-15 21:25:41 +00:00
|
|
|
logger.exception('Cannot find notification method: %s', ex.message)
|
2014-09-22 16:52:57 +00:00
|
|
|
raise JobException('Cannot find notification method: %s' % ex.message)
|
2014-07-18 02:51:58 +00:00
|
|
|
except InvalidNotificationEventException as ex:
|
2015-07-15 21:25:41 +00:00
|
|
|
logger.exception('Cannot find notification event: %s', ex.message)
|
2014-09-22 16:52:57 +00:00
|
|
|
raise JobException('Cannot find notification event: %s' % ex.message)
|
|
|
|
|
|
|
|
method_handler.perform(notification, event_handler, job_details)
|
2014-07-18 02:51:58 +00:00
|
|
|
|
|
|
|
|
2014-09-22 16:52:57 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
worker = NotificationWorker(notification_queue, poll_period_seconds=10, reservation_seconds=30,
|
|
|
|
retry_after_seconds=30)
|
|
|
|
worker.start()
|