change when we send job notifications to avoid a race condition

success/failure notifications for *playbooks* include summary data about
the hosts in based on the contents of the playbook_on_stats event

the current implementation suffers from a number of race conditions that
sometimes can cause that data to be missing or incomplete; this change
makes it so that for *playbooks* we build (and send) the notification in
response to the playbook_on_stats event, not the EOF event
This commit is contained in:
Ryan Petrello
2020-03-13 17:36:20 -04:00
parent a725778b17
commit d40a5dec8f
3 changed files with 37 additions and 15 deletions

View File

@@ -602,6 +602,23 @@ def handle_work_error(task_id, *args, **kwargs):
pass
@task(queue=get_local_queuename)
def handle_success_and_failure_notifications(job_id):
uj = UnifiedJob.objects.get(pk=job_id)
retries = 0
while retries < 5:
if uj.finished:
uj.send_notification_templates('succeeded' if uj.status == 'successful' else 'failed')
break
else:
# wait a few seconds to avoid a race where the
# events are persisted _before_ the UJ.status
# changes from running -> successful
retries += 1
time.sleep(1)
uj = UnifiedJob.objects.get(pk=job_id)
@task(queue=get_local_queuename)
def update_inventory_computed_fields(inventory_id):
'''