diff --git a/awx/main/models/notifications.py b/awx/main/models/notifications.py index 8f16cf4af8..222127f1d6 100644 --- a/awx/main/models/notifications.py +++ b/awx/main/models/notifications.py @@ -242,15 +242,16 @@ class JobNotificationMixin(object): else: notification_template_type = 'error' all_notification_templates = set(notification_templates.get(notification_template_type, [])) - if status_str != 'running': - all_notification_templates.update(notification_templates.get('any', [])) - try: - (notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)() - except AttributeError: - raise NotImplementedError("build_notification_%s_message() does not exist" % status_str) + if len(all_notification_templates): + if status_str != 'running': + all_notification_templates.update(notification_templates.get('any', [])) + try: + (notification_subject, notification_body) = getattr(self, 'build_notification_%s_message' % status_str)() + except AttributeError: + raise NotImplementedError("build_notification_%s_message() does not exist" % status_str) - def send_it(): - send_notifications.delay([n.generate_notification(notification_subject, notification_body).id - for n in all_notification_templates], - job_id=self.id) - connection.on_commit(send_it) + def send_it(): + send_notifications.delay([n.generate_notification(notification_subject, notification_body).id + for n in all_notification_templates], + job_id=self.id) + connection.on_commit(send_it) diff --git a/awx/main/scheduler/task_manager.py b/awx/main/scheduler/task_manager.py index 6c25fbef4a..b79abbad0d 100644 --- a/awx/main/scheduler/task_manager.py +++ b/awx/main/scheduler/task_manager.py @@ -194,7 +194,7 @@ class TaskManager(): if status_changed: workflow_job.websocket_emit_status(workflow_job.status) # Operations whose queries rely on modifications made during the atomic scheduling session - connection.on_commit(lambda: workflow_job.send_notification_templates('succeeded' if workflow_job.status == 'successful' else 'failed')) + workflow_job.send_notification_templates('succeeded' if workflow_job.status == 'successful' else 'failed') if workflow_job.spawned_by_workflow: schedule_task_manager() return result @@ -235,7 +235,7 @@ class TaskManager(): else: if type(task) is WorkflowJob: task.status = 'running' - connection.on_commit(lambda: task.send_notification_templates('running')) + task.send_notification_templates('running') logger.debug('Transitioning %s to running status.', task.log_format) schedule_task_manager() elif not task.supports_isolation() and rampart_group.controller_id: