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 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. # if it hasn't been specified, then we're just doing a normal save.
update_fields = kwargs.get('update_fields', []) 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) res = self.event_data.get('res', None)
# Workaround for Ansible 1.2, where the runner_on_async_ok event is # 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 # created even when the async task failed. Change the event to be
@@ -660,6 +664,7 @@ class JobEvent(BaseModel):
self.parent = self._find_parent() self.parent = self._find_parent()
update_fields.extend(['play', 'task', 'parent']) update_fields.extend(['play', 'task', 'parent'])
super(JobEvent, self).save(*args, **kwargs) super(JobEvent, self).save(*args, **kwargs)
if not from_parent_update:
self.update_parent_failed_and_changed() self.update_parent_failed_and_changed()
self.update_hosts() self.update_hosts()
self.update_host_summary_from_stats() self.update_host_summary_from_stats()
@@ -676,7 +681,7 @@ class JobEvent(BaseModel):
parent.changed = True parent.changed = True
update_fields.append('changed') update_fields.append('changed')
if update_fields: 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() parent.update_parent_failed_and_changed()
def update_hosts(self, extra_hosts=None): def update_hosts(self, extra_hosts=None):

View File

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