Convert over to notifications system. Note this is incomplete
This commit is contained in:
parent
de8e898ad0
commit
8d7493cb86
17 changed files with 432 additions and 166 deletions
54
workers/notificationworker.py
Normal file
54
workers/notificationworker.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
import logging
|
||||
import argparse
|
||||
import requests
|
||||
import json
|
||||
|
||||
from app import notification_queue
|
||||
from workers.worker import Worker
|
||||
|
||||
from endpoints.notificationmethod import NotificationMethod, InvalidNotificationMethodException
|
||||
from endpoints.notificationevent import NotificationEvent, InvalidNotificationEventException
|
||||
|
||||
from data import model
|
||||
|
||||
root_logger = logging.getLogger('')
|
||||
root_logger.setLevel(logging.DEBUG)
|
||||
|
||||
FORMAT = '%(asctime)-15s - %(levelname)s - %(pathname)s - %(funcName)s - %(message)s'
|
||||
formatter = logging.Formatter(FORMAT)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class NotificationWorker(Worker):
|
||||
def process_queue_item(self, job_details):
|
||||
notification_id = job_details['notification_id'];
|
||||
notification = model.lookup_repo_notification(notification_id)
|
||||
|
||||
print job_details
|
||||
print notification
|
||||
|
||||
if not notification:
|
||||
# Probably deleted.
|
||||
return True
|
||||
|
||||
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:
|
||||
logger.exception('Cannot find notification method: %s' % ex.message)
|
||||
return False
|
||||
except InvalidNotificationEventException as ex:
|
||||
logger.exception('Cannot find notification method: %s' % ex.message)
|
||||
return False
|
||||
|
||||
return method_handler.perform(notification, event_handler, job_details)
|
||||
|
||||
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
|
||||
|
||||
worker = NotificationWorker(notification_queue, poll_period_seconds=15,
|
||||
reservation_seconds=3600)
|
||||
worker.start()
|
Reference in a new issue