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:
parent
3d0d75e897
commit
d8383a4d69
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -311,13 +311,11 @@ 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():
|
||||
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():
|
||||
if not source in inventory_sources_found and source.needs_update_on_launch:
|
||||
dependencies.append(source.create_inventory_update(launch_type='dependency'))
|
||||
return dependencies
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user