mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 06:29:31 -02:30
remove duplicated get_latest calls
This commit is contained in:
@@ -311,15 +311,13 @@ class TaskManager():
|
|||||||
return None
|
return None
|
||||||
return latest_inventory_update.first()
|
return latest_inventory_update.first()
|
||||||
|
|
||||||
def should_update_inventory_source(self, job, inventory_source):
|
def should_update_inventory_source(self, job, latest_inventory_update):
|
||||||
now = tz_now()
|
now = tz_now()
|
||||||
|
|
||||||
# Already processed dependencies for this job
|
# Already processed dependencies for this job
|
||||||
if job.dependent_jobs.all():
|
if job.dependent_jobs.all():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
latest_inventory_update = self.get_latest_inventory_update(inventory_source)
|
|
||||||
|
|
||||||
if latest_inventory_update is None:
|
if latest_inventory_update is None:
|
||||||
return True
|
return True
|
||||||
'''
|
'''
|
||||||
@@ -343,13 +341,11 @@ class TaskManager():
|
|||||||
return None
|
return None
|
||||||
return latest_project_update.first()
|
return latest_project_update.first()
|
||||||
|
|
||||||
def should_update_related_project(self, job):
|
def should_update_related_project(self, job, latest_project_update):
|
||||||
now = tz_now()
|
now = tz_now()
|
||||||
if job.dependent_jobs.all():
|
if job.dependent_jobs.all():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
latest_project_update = self.get_latest_project_update(job)
|
|
||||||
|
|
||||||
if latest_project_update is None:
|
if latest_project_update is None:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -385,11 +381,11 @@ class TaskManager():
|
|||||||
if type(task) is Job:
|
if type(task) is Job:
|
||||||
# TODO: Can remove task.project None check after scan-job-default-playbook is removed
|
# TODO: Can remove task.project None check after scan-job-default-playbook is removed
|
||||||
if task.project is not None and task.project.scm_update_on_launch is True:
|
if task.project is not None and task.project.scm_update_on_launch is True:
|
||||||
if self.should_update_related_project(task):
|
latest_project_update = self.get_latest_project_update(task)
|
||||||
|
if self.should_update_related_project(task, latest_project_update):
|
||||||
project_task = self.create_project_update(task)
|
project_task = self.create_project_update(task)
|
||||||
dependencies.append(project_task)
|
dependencies.append(project_task)
|
||||||
else:
|
else:
|
||||||
latest_project_update = self.get_latest_project_update(task)
|
|
||||||
if latest_project_update.status in ['waiting', 'pending', 'running']:
|
if latest_project_update.status in ['waiting', 'pending', 'running']:
|
||||||
dependencies.append(latest_project_update)
|
dependencies.append(latest_project_update)
|
||||||
|
|
||||||
@@ -398,11 +394,11 @@ class TaskManager():
|
|||||||
for inventory_source in [invsrc for invsrc in self.all_inventory_sources if invsrc.inventory == task.inventory]:
|
for inventory_source in [invsrc for invsrc in self.all_inventory_sources if invsrc.inventory == task.inventory]:
|
||||||
if not inventory_source.update_on_launch:
|
if not inventory_source.update_on_launch:
|
||||||
continue
|
continue
|
||||||
if self.should_update_inventory_source(task, inventory_source):
|
latest_inventory_update = self.get_latest_inventory_update(inventory_source)
|
||||||
|
if self.should_update_inventory_source(task, latest_inventory_update):
|
||||||
inventory_task = self.create_inventory_update(task, inventory_source)
|
inventory_task = self.create_inventory_update(task, inventory_source)
|
||||||
dependencies.append(inventory_task)
|
dependencies.append(inventory_task)
|
||||||
else:
|
else:
|
||||||
latest_inventory_update = self.get_latest_inventory_update(inventory_source)
|
|
||||||
if latest_inventory_update.status in ['waiting', 'pending', 'running']:
|
if latest_inventory_update.status in ['waiting', 'pending', 'running']:
|
||||||
dependencies.append(latest_inventory_update)
|
dependencies.append(latest_inventory_update)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user