From d8383a4d69fde1360acc6ad93904394d3f3e47db Mon Sep 17 00:00:00 2001 From: Chris Church Date: Wed, 26 Mar 2014 16:40:52 -0400 Subject: [PATCH] AC-1076 Exposed scm_update_cache_timeout for projects, added needs_update_on_launch property to project and inventory source models. --- awx/api/serializers.py | 3 ++- awx/main/models/inventory.py | 9 +++++++++ awx/main/models/jobs.py | 10 ++++------ awx/main/models/projects.py | 9 +++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index 5ee8d6c341..7e3ebcc41a 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -491,7 +491,8 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer): class Meta: model = Project - fields = ('*', 'scm_delete_on_next_update', 'scm_update_on_launch') + \ + fields = ('*', 'scm_delete_on_next_update', 'scm_update_on_launch', + 'scm_update_cache_timeout') + \ ('last_update_failed', 'last_updated') # Backwards compatibility def get_related(self, obj): diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index 391b34b45b..2b57a5e508 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -661,6 +661,15 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions): def create_inventory_update(self, **kwargs): return self._create_unified_job_instance(**kwargs) + @property + def needs_update_on_launch(self): + if self.active and self.source and self.update_on_launch: + if not self.last_job_run: + return True + if (self.last_job_run + datetime.timedelta(seconds=self.update_cache_timeout)) <= now(): + return True + return False + def update_signature(self, **kwargs): if self.can_update: inventory_update = self.create_inventory_update() diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 26214f9752..9e507d0552 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -311,14 +311,12 @@ class Job(UnifiedJob, JobOptions): if type(obj) == InventoryUpdate: if obj.inventory_source in inventory_sources: inventory_sources_found.append(obj.inventory_source) - if not project_found and self.project.scm_update_on_launch: - if not self.project.last_job_run + datetime.timedelta(seconds=self.project.scm_update_cache_timeout) > now(): - dependencies.append(self.project.create_project_update(launch_type='dependency')) + if not project_found and self.project.needs_update_on_launch: + dependencies.append(self.project.create_project_update(launch_type='dependency')) if inventory_sources.count(): # and not has_setup_failures? Probably handled as an error scenario in the task runner for source in inventory_sources: - if not source in inventory_sources_found: - if not source.last_job_run + datetime.timedelta(seconds=source.update_cache_timeout) > now(): - dependencies.append(source.create_inventory_update(launch_type='dependency')) + if not source in inventory_sources_found and source.needs_update_on_launch: + dependencies.append(source.create_inventory_update(launch_type='dependency')) return dependencies def signal_start(self, **kwargs): diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index 96785975ae..ed6fee7ec1 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -297,6 +297,15 @@ class Project(UnifiedJobTemplate, ProjectOptions): kwargs['scm_delete_on_update'] = True return self._create_unified_job_instance(**kwargs) + @property + def needs_update_on_launch(self): + if self.active and self.scm_type and self.scm_update_on_launch: + if not self.last_job_run: + return True + if (self.last_job_run + datetime.timedelta(seconds=self.scm_update_cache_timeout)) <= now(): + return True + return False + def update_signature(self, **kwargs): if self.can_update: project_update = self.create_project_update()