1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 08:21:15 +03:00

associate notifications with job before sending notifications

related to #3391
This commit is contained in:
Chris Meyers 2016-12-16 11:26:16 -05:00
parent ef1f77bf8e
commit bf23f6a52c

View File

@ -109,8 +109,12 @@ def send_notifications(notification_list, job_id=None):
raise TypeError("notification_list should be of type list") raise TypeError("notification_list should be of type list")
if job_id is not None: if job_id is not None:
job_actual = UnifiedJob.objects.get(id=job_id) job_actual = UnifiedJob.objects.get(id=job_id)
for notification_id in notification_list:
notification = Notification.objects.get(id=notification_id) notifications = Notification.objects.filter(id__in=notification_list)
if job_id is not None:
job_actual.notifications.add(*notifications)
for notification in notifications:
try: try:
sent = notification.notification_template.send(notification.subject, notification.body) sent = notification.notification_template.send(notification.subject, notification.body)
notification.status = "successful" notification.status = "successful"
@ -121,8 +125,6 @@ def send_notifications(notification_list, job_id=None):
notification.error = smart_str(e) notification.error = smart_str(e)
finally: finally:
notification.save() notification.save()
if job_id is not None:
job_actual.notifications.add(notification)
@task(bind=True, queue='default') @task(bind=True, queue='default')