mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Attempt to wait for job host summaries
Sometimes the job host summaries can land a little later after the job has finished so sometimes events are still filtering in when the notifications are triggered
This commit is contained in:
parent
ea024c7e11
commit
8fcc194c82
@ -6,6 +6,7 @@ import hmac
|
||||
import json
|
||||
import yaml
|
||||
import logging
|
||||
import time
|
||||
from urlparse import urljoin
|
||||
|
||||
# Django
|
||||
@ -680,9 +681,17 @@ class Job(UnifiedJob, JobOptions):
|
||||
dependencies.append(source.create_inventory_update(launch_type='dependency'))
|
||||
return dependencies
|
||||
|
||||
def notification_data(self):
|
||||
def notification_data(self, block=5):
|
||||
data = super(Job, self).notification_data()
|
||||
all_hosts = {}
|
||||
# NOTE: Probably related to job event slowness, remove at some point -matburt
|
||||
if block:
|
||||
summaries = self.job_host_summaries.all()
|
||||
while block > 0 and not len(summaries):
|
||||
time.sleep(1)
|
||||
block -= 1
|
||||
else:
|
||||
summaries = self.job_host_summaries.all()
|
||||
for h in self.job_host_summaries.all():
|
||||
all_hosts[h.host_name] = dict(failed=h.failed,
|
||||
changed=h.changed,
|
||||
|
@ -214,6 +214,9 @@ def handle_work_success(self, result, task_actual):
|
||||
friendly_name = "System Job"
|
||||
else:
|
||||
return
|
||||
|
||||
all_notification_templates = set(notification_templates.get('success', []) + notification_templates.get('any', []))
|
||||
if len(all_notification_templates):
|
||||
notification_body = instance.notification_data()
|
||||
notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name,
|
||||
task_actual['id'],
|
||||
@ -221,7 +224,7 @@ def handle_work_success(self, result, task_actual):
|
||||
notification_body['url'])
|
||||
notification_body['friendly_name'] = friendly_name
|
||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||
for n in set(notification_templates.get('success', []) + notification_templates.get('any', []))],
|
||||
for n in all_notification_templates],
|
||||
job_id=task_actual['id'])
|
||||
|
||||
@task(bind=True)
|
||||
@ -277,6 +280,9 @@ def handle_work_error(self, task_id, subtasks=None):
|
||||
(first_task_type, first_task_name, first_task_id)
|
||||
instance.save()
|
||||
instance.socketio_emit_status("failed")
|
||||
|
||||
all_notification_templates = set(notification_templates.get('error', []) + notification_templates.get('any', []))
|
||||
if len(all_notification_templates):
|
||||
notification_body = first_task.notification_data()
|
||||
notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name,
|
||||
first_task_id,
|
||||
@ -284,7 +290,7 @@ def handle_work_error(self, task_id, subtasks=None):
|
||||
notification_body['url'])
|
||||
notification_body['friendly_name'] = first_task_friendly_name
|
||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||
for n in set(notification_templates.get('error', []) + notification_templates.get('any', []))],
|
||||
for n in all_notification_templates],
|
||||
job_id=first_task_id)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user