Update the worker code to better handle exceptions, fix the utcdate issue and make sure we send the proper retry. Also updates notification workers to send JobExceptions rather than returning true or false
This commit is contained in:
parent
8c00eabedd
commit
f23038c6ee
6 changed files with 62 additions and 60 deletions
|
@ -8,6 +8,7 @@ from workers.worker import Worker
|
|||
|
||||
from endpoints.notificationmethod import NotificationMethod, InvalidNotificationMethodException
|
||||
from endpoints.notificationevent import NotificationEvent, InvalidNotificationEventException
|
||||
from workers.worker import JobException
|
||||
|
||||
from data import model
|
||||
|
||||
|
@ -29,7 +30,7 @@ class NotificationWorker(Worker):
|
|||
notification = model.get_repo_notification(repo_namespace, repo_name, notification_uuid)
|
||||
if not notification:
|
||||
# Probably deleted.
|
||||
return True
|
||||
return
|
||||
|
||||
event_name = notification.event.name
|
||||
method_name = notification.method.name
|
||||
|
@ -39,15 +40,17 @@ class NotificationWorker(Worker):
|
|||
method_handler = NotificationMethod.get_method(method_name)
|
||||
except InvalidNotificationMethodException as ex:
|
||||
logger.exception('Cannot find notification method: %s' % ex.message)
|
||||
return False
|
||||
raise JobException('Cannot find notification method: %s' % ex.message)
|
||||
except InvalidNotificationEventException as ex:
|
||||
logger.exception('Cannot find notification method: %s' % ex.message)
|
||||
return False
|
||||
logger.exception('Cannot find notification event: %s' % ex.message)
|
||||
raise JobException('Cannot find notification event: %s' % ex.message)
|
||||
|
||||
return method_handler.perform(notification, event_handler, job_details)
|
||||
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()
|
||||
if __name__ == "__main__":
|
||||
logging.config.fileConfig('conf/logging.conf', disable_existing_loggers=False)
|
||||
|
||||
worker = NotificationWorker(notification_queue, poll_period_seconds=10, reservation_seconds=30,
|
||||
retry_after_seconds=30)
|
||||
worker.start()
|
||||
|
|
Reference in a new issue