Fix bugs in the initial impl of the notification event and notification method libs.

This commit is contained in:
Joseph Schorr 2014-07-18 11:52:36 -04:00
parent 8d7493cb86
commit df7b8d651c
2 changed files with 15 additions and 8 deletions

View file

@ -50,14 +50,20 @@ class QuayNotificationMethod(NotificationMethod):
return 'quay_notification'
def perform(self, notification, event_handler, notification_data):
config_data = json.loads(notification.config_json)
repository_id = notification_data['repository_id']
repository = model.lookup_repository(repository_id)
if not repository:
# Probably deleted.
return True
model.create_notification(event_handler.event_name(),
repository.namespace, metadata=notification_data['event_data'])
target_name = config_data['target'];
target = model.get_user(target_name)
if not target:
return False
model.create_notification(event_handler.event_name(), target,
metadata=notification_data['event_data'])
return True
@ -78,7 +84,8 @@ class EmailMethod(NotificationMethod):
msg.html = event_handler.get_message(notification_data)
try:
mail.send(msg)
with app.app_context():
mail.send(msg)
except Exception as ex:
logger.exception('Email was unable to be sent: %s' % ex.message)
return False