1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

AC-620 Some cleanup of job events to reduce extra queries, test case to reproduce deadlocks.

This commit is contained in:
Chris Church 2013-11-21 17:37:14 -05:00
parent a1ff025488
commit 9b49e80dc5
2 changed files with 58 additions and 55 deletions

View File

@ -615,6 +615,10 @@ class JobEvent(BaseModel):
# If update_fields has been specified, add our field names to it,
# if it hasn't been specified, then we're just doing a normal save.
update_fields = kwargs.get('update_fields', [])
# Skip normal checks on save if we're only updating failed/changed
# flags triggered from a child event.
from_parent_update = kwargs.pop('from_parent_update', False)
if not from_parent_update:
res = self.event_data.get('res', None)
# Workaround for Ansible 1.2, where the runner_on_async_ok event is
# created even when the async task failed. Change the event to be
@ -660,6 +664,7 @@ class JobEvent(BaseModel):
self.parent = self._find_parent()
update_fields.extend(['play', 'task', 'parent'])
super(JobEvent, self).save(*args, **kwargs)
if not from_parent_update:
self.update_parent_failed_and_changed()
self.update_hosts()
self.update_host_summary_from_stats()
@ -676,7 +681,7 @@ class JobEvent(BaseModel):
parent.changed = True
update_fields.append('changed')
if update_fields:
parent.save(update_fields=update_fields)
parent.save(update_fields=update_fields, from_parent_update=True)
parent.update_parent_failed_and_changed()
def update_hosts(self, extra_hosts=None):

View File

@ -1364,16 +1364,14 @@ class JobTransactionTest(BaseJobTestMixin, django.test.LiveServerTestCase):
finally:
t.join(20)
# FIXME: This test isn't working for now.
def _test_get_job_detail_while_job_running(self):
self.proj_async = self.make_project('async', 'async test',
self.user_sue, TEST_ASYNC_PLAYBOOK)
self.org_eng.projects.add(self.proj_async)
job = self.job_ops_east_run
job.project = self.proj_async
job.playbook = self.proj_async.playbooks[0]
job.verbosity = 3
job.save()
def test_for_job_deadlocks(self):
# Create lots of extra test hosts to trigger job event callbacks
job = self.job_eng_run
inv = job.inventory
for x in xrange(100):
h = inv.hosts.create(name='local-%d' % x)
for g in inv.groups.all():
g.hosts.add(h)
job_detail_url = reverse('api:job_detail', args=(job.pk,))
job_detail_url = urlparse.urljoin(self.live_server_url, job_detail_url)