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

AC-1076 Exposed scm_update_cache_timeout for projects, added needs_update_on_launch property to project and inventory source models.

This commit is contained in:
Chris Church 2014-03-26 16:40:52 -04:00
parent 3d0d75e897
commit d8383a4d69
4 changed files with 24 additions and 7 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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):

View File

@ -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()