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:
parent
ea024c7e11
commit
8fcc194c82
@ -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,
|
||||||
|
@ -214,15 +214,18 @@ def handle_work_success(self, result, task_actual):
|
|||||||
friendly_name = "System Job"
|
friendly_name = "System Job"
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
notification_body = instance.notification_data()
|
|
||||||
notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name,
|
all_notification_templates = set(notification_templates.get('success', []) + notification_templates.get('any', []))
|
||||||
task_actual['id'],
|
if len(all_notification_templates):
|
||||||
smart_str(instance_name),
|
notification_body = instance.notification_data()
|
||||||
notification_body['url'])
|
notification_subject = "{} #{} '{}' succeeded on Ansible Tower: {}".format(friendly_name,
|
||||||
notification_body['friendly_name'] = friendly_name
|
task_actual['id'],
|
||||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
smart_str(instance_name),
|
||||||
for n in set(notification_templates.get('success', []) + notification_templates.get('any', []))],
|
notification_body['url'])
|
||||||
job_id=task_actual['id'])
|
notification_body['friendly_name'] = friendly_name
|
||||||
|
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||||
|
for n in all_notification_templates],
|
||||||
|
job_id=task_actual['id'])
|
||||||
|
|
||||||
@task(bind=True)
|
@task(bind=True)
|
||||||
def handle_work_error(self, task_id, subtasks=None):
|
def handle_work_error(self, task_id, subtasks=None):
|
||||||
@ -277,15 +280,18 @@ 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")
|
||||||
notification_body = first_task.notification_data()
|
|
||||||
notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name,
|
all_notification_templates = set(notification_templates.get('error', []) + notification_templates.get('any', []))
|
||||||
first_task_id,
|
if len(all_notification_templates):
|
||||||
smart_str(first_task_name),
|
notification_body = first_task.notification_data()
|
||||||
notification_body['url'])
|
notification_subject = "{} #{} '{}' failed on Ansible Tower: {}".format(first_task_friendly_name,
|
||||||
notification_body['friendly_name'] = first_task_friendly_name
|
first_task_id,
|
||||||
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
smart_str(first_task_name),
|
||||||
for n in set(notification_templates.get('error', []) + notification_templates.get('any', []))],
|
notification_body['url'])
|
||||||
job_id=first_task_id)
|
notification_body['friendly_name'] = first_task_friendly_name
|
||||||
|
send_notifications.delay([n.generate_notification(notification_subject, notification_body).id
|
||||||
|
for n in all_notification_templates],
|
||||||
|
job_id=first_task_id)
|
||||||
|
|
||||||
|
|
||||||
@task()
|
@task()
|
||||||
|
Loading…
Reference in New Issue
Block a user