change host -> last_job_id bulk update query to avoid locking issues

see: https://github.com/ansible/awx/issues/8145
This commit is contained in:
Ryan Petrello 2020-09-22 15:54:26 -04:00
parent 3184bccb33
commit 89ff8e1f3e
No known key found for this signature in database
GPG Key ID: F2AA5F2122351777

View File

@ -520,13 +520,21 @@ class JobEvent(BasePlaybookEvent):
(summary['host_id'], summary['id'])
for summary in JobHostSummary.objects.filter(job_id=job.id).values('id', 'host_id')
)
updated_hosts = set()
for h in all_hosts:
# if the hostname *shows up* in the playbook_on_stats event
if h.name in hostnames:
h.last_job_id = job.id
updated_hosts.add(h)
if h.id in host_mapping:
h.last_job_host_summary_id = host_mapping[h.id]
Host.objects.bulk_update(all_hosts, ['last_job_id', 'last_job_host_summary_id'])
updated_hosts.add(h)
Host.objects.bulk_update(
list(updated_hosts),
['last_job_id', 'last_job_host_summary_id'],
batch_size=100
)
@property