mirror of
https://github.com/ansible/awx.git
synced 2026-03-27 13:55:04 -02:30
associate notifications with job before sending notifications
related to #3391
This commit is contained in:
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user