1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +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:
Matthew Jones 2016-08-10 11:28:09 -04:00
parent ea024c7e11
commit 8fcc194c82
2 changed files with 34 additions and 19 deletions

View File

@ -6,6 +6,7 @@ import hmac
import json import json
import yaml import yaml
import logging import logging
import time
from urlparse import urljoin from urlparse import urljoin
# Django # Django
@ -680,9 +681,17 @@ class Job(UnifiedJob, JobOptions):
dependencies.append(source.create_inventory_update(launch_type='dependency')) dependencies.append(source.create_inventory_update(launch_type='dependency'))
return dependencies return dependencies
def notification_data(self): def notification_data(self, block=5):
data = super(Job, self).notification_data() data = super(Job, self).notification_data()
all_hosts = {} 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(): for h in self.job_host_summaries.all():
all_hosts[h.host_name] = dict(failed=h.failed, all_hosts[h.host_name] = dict(failed=h.failed,
changed=h.changed, changed=h.changed,

View File

@ -214,6 +214,9 @@ def handle_work_success(self, result, task_actual):
friendly_name = "System Job" friendly_name = "System Job"
else: else:
return return
all_notification_templates = set(notification_templates.get('success', []) + notification_templates.get('any', []))
if len(all_notification_templates):
notification_body = instance.notification_data() notification_body = instance.notification_data()
notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name, notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name,
task_actual['id'], task_actual['id'],
@ -221,7 +224,7 @@ def handle_work_success(self, result, task_actual):
notification_body['url']) notification_body['url'])
notification_body['friendly_name'] = friendly_name notification_body['friendly_name'] = friendly_name
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id 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']) job_id=task_actual['id'])
@task(bind=True) @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) (first_task_type, first_task_name, first_task_id)
instance.save() instance.save()
instance.socketio_emit_status("failed") 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_body = first_task.notification_data()
notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name, notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name,
first_task_id, first_task_id,
@ -284,7 +290,7 @@ def handle_work_error(self, task_id, subtasks=None):
notification_body['url']) notification_body['url'])
notification_body['friendly_name'] = first_task_friendly_name notification_body['friendly_name'] = first_task_friendly_name
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id 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) job_id=first_task_id)