def post(self, namespace_name, repository_name): parsed = request.get_json() method_handler = NotificationMethod.get_method(parsed["method"]) try: method_handler.validate(namespace_name, repository_name, parsed["config"]) except CannotValidateNotificationMethodException as ex: raise request_error(message=ex.message) new_notification = model.create_repo_notification( namespace_name, repository_name, parsed["event"], parsed["method"], parsed["config"], parsed["eventConfig"], parsed.get("title"), ) log_action( "add_repo_notification", namespace_name, { "repo": repository_name, "namespace": namespace_name, "notification_id": new_notification.uuid, "event": new_notification.event_name, "method": new_notification.method_name, }, repo_name=repository_name, ) return new_notification.to_dict(), 201
def process_queue_item(self, job_details): notification = model.get_enabled_notification( job_details['notification_uuid']) if notification is None: return 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) raise JobException('Cannot find notification method: %s' % ex.message) except InvalidNotificationEventException as ex: logger.exception('Cannot find notification event: %s', ex.message) raise JobException('Cannot find notification event: %s' % ex.message) if event_handler.should_perform(job_details['event_data'], notification): try: method_handler.perform(notification, event_handler, job_details) model.reset_number_of_failures_to_zero(notification) except (JobException, KeyError) as exc: model.increment_notification_failure_count(notification) raise exc
def post(self, namespace_name, repository_name): parsed = request.get_json() method_handler = NotificationMethod.get_method(parsed['method']) try: method_handler.validate(namespace_name, repository_name, parsed['config']) except CannotValidateNotificationMethodException as ex: raise request_error(message=ex.message) new_notification = model.create_repo_notification( namespace_name, repository_name, parsed['event'], parsed['method'], parsed['config'], parsed['eventConfig'], parsed.get('title')) log_action('add_repo_notification', namespace_name, { 'repo': repository_name, 'namespace': namespace_name, 'notification_id': new_notification.uuid, 'event': new_notification.event_name, 'method': new_notification.method_name }, repo_name=repository_name) return new_notification.to_dict(), 201