mirror of
https://github.com/ansible/awx.git
synced 2026-05-23 08:37:48 -02:30
AC-546 Fixed transaction management for running tasks.
This commit is contained in:
@@ -48,6 +48,9 @@ class BaseTask(Task):
|
|||||||
Reload model from database and update the given fields.
|
Reload model from database and update the given fields.
|
||||||
'''
|
'''
|
||||||
output_replacements = updates.pop('output_replacements', None) or []
|
output_replacements = updates.pop('output_replacements', None) or []
|
||||||
|
# Commit outstanding transaction so that we fetch the latest object
|
||||||
|
# from the database.
|
||||||
|
transaction.commit()
|
||||||
instance = self.model.objects.get(pk=pk)
|
instance = self.model.objects.get(pk=pk)
|
||||||
if updates:
|
if updates:
|
||||||
update_fields = []
|
update_fields = []
|
||||||
@@ -60,6 +63,7 @@ class BaseTask(Task):
|
|||||||
if field == 'status':
|
if field == 'status':
|
||||||
update_fields.append('failed')
|
update_fields.append('failed')
|
||||||
instance.save(update_fields=update_fields)
|
instance.save(update_fields=update_fields)
|
||||||
|
transaction.commit()
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
def get_path_to(self, *args):
|
def get_path_to(self, *args):
|
||||||
@@ -237,6 +241,7 @@ class BaseTask(Task):
|
|||||||
obj.result_traceback += '\nCanceled stuck %s.' % unicode(self.model._meta.verbose_name)
|
obj.result_traceback += '\nCanceled stuck %s.' % unicode(self.model._meta.verbose_name)
|
||||||
obj.save(update_fields=['status', 'result_traceback'])
|
obj.save(update_fields=['status', 'result_traceback'])
|
||||||
|
|
||||||
|
@transaction.commit_on_success
|
||||||
def run(self, pk, **kwargs):
|
def run(self, pk, **kwargs):
|
||||||
'''
|
'''
|
||||||
Run the job/task using ansible-playbook and capture its output.
|
Run the job/task using ansible-playbook and capture its output.
|
||||||
@@ -817,7 +822,7 @@ class RunInventoryUpdate(BaseTask):
|
|||||||
iu_qs = InventoryUpdate.objects.filter(inventory_source__inventory=inventory, status__in=('pending', 'running'))
|
iu_qs = InventoryUpdate.objects.filter(inventory_source__inventory=inventory, status__in=('pending', 'running'))
|
||||||
iu_qs = iu_qs.exclude(pk=inventory_update.pk)
|
iu_qs = iu_qs.exclude(pk=inventory_update.pk)
|
||||||
if jobs_qs.count() or iu_qs.count():
|
if jobs_qs.count() or iu_qs.count():
|
||||||
#print 'inventory update %d waiting on' % pk, jobs_qs, iu_qs
|
print 'inventory update %d waiting on' % pk, jobs_qs, iu_qs
|
||||||
inventory_update = self.update_model(pk, status='waiting')
|
inventory_update = self.update_model(pk, status='waiting')
|
||||||
time.sleep(4.0)
|
time.sleep(4.0)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user