Trigger running notifications in WFJs and edit unit test

This commit is contained in:
beeankha
2019-06-03 20:57:08 -04:00
parent 98fa1fc813
commit 8d6e1f0927
5 changed files with 29 additions and 58 deletions

View File

@@ -7,6 +7,7 @@ import logging
from django.db import models
from django.conf import settings
from django.core.mail.message import EmailMessage
from django.db import connection
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import smart_str, force_text
@@ -240,12 +241,16 @@ class JobNotificationMixin(object):
notification_template_type = 'started'
else:
notification_template_type = 'error'
all_notification_templates = set(notification_templates.get(notification_template_type, []) + notification_templates.get('any', []))
if len(all_notification_templates):
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)
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)
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)