From 300396c7ce5a36782aa0225b5b18d5ed1aca37fa Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Thu, 13 Nov 2014 13:47:23 -0500 Subject: [PATCH] Extend cache timeout to schedule runner also, block running a schedule of an inventory update or a project update if its schedule places it within that time also --- awx/main/models/inventory.py | 8 ++++++++ awx/main/models/jobs.py | 4 ++++ awx/main/models/projects.py | 8 ++++++++ awx/main/tasks.py | 3 +++ 4 files changed, 23 insertions(+) diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index fa61b67884..928972dad1 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -995,6 +995,14 @@ class InventorySource(UnifiedJobTemplate, InventorySourceOptions): def create_inventory_update(self, **kwargs): return self.create_unified_job(**kwargs) + @property + def cache_timeout_blocked(self): + if not self.last_job_run: + return False + if (self.last_job_run + datetime.timedelta(seconds=self.update_cache_timeout)) > now(): + return True + return False + @property def needs_update_on_launch(self): if self.active and self.source and self.update_on_launch: diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index 4a9fc5861d..dff8b2a5f1 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -370,6 +370,10 @@ class Job(UnifiedJob, JobOptions): return False return False + @property + def cache_timeout_blocked(self): + return False + @property def task_impact(self): # NOTE: We sorta have to assume the host count matches and that forks default to 5 diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index cd71fcb1b2..b713c3c557 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -298,6 +298,14 @@ class Project(UnifiedJobTemplate, ProjectOptions): def create_project_update(self, **kwargs): return self.create_unified_job(**kwargs) + @property + def cache_timeout_blocked(self): + if not self.last_job_run: + return False + if (self.last_job_run + datetime.timedelta(seconds=self.update_cache_timeout)) > now(): + return True + return False + @property def needs_update_on_launch(self): if self.active and self.scm_type and self.scm_update_on_launch: diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 4cb8c41da2..f9b09ea8e6 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -93,6 +93,9 @@ def tower_periodic_scheduler(self): for schedule in schedules: template = schedule.unified_job_template schedule.save() # To update next_run timestamp. + if template.cache_timeout_blocked: + logger.warn("Cache timeout is in the future, bypassing schedule for template %s" % str(template.id)) + continue new_unified_job = template.create_unified_job(launch_type='scheduled', schedule=schedule) can_start = new_unified_job.signal_start(**schedule.extra_data) if not can_start: