From e8a837ea1102507e5ada427c789b87f0a0de7fc3 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Mon, 8 Dec 2014 10:51:16 -0500 Subject: [PATCH] Add a default maximum of 10 jobs waiting from a job template if launched by a schedule --- awx/main/models/jobs.py | 4 ++++ awx/settings/defaults.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index e7406d28fa..d5303134f2 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -286,6 +286,10 @@ class JobTemplate(UnifiedJobTemplate, JobOptions): @property def cache_timeout_blocked(self): + if Job.objects.filter(job_template=self, status__in=['pending', 'waiting', 'running']).count() > getattr(settings, 'SCHEDULE_MAX_JOBS', 10): + logger.error("Job template %s could not be started because there are more than %s other jobs from that template waiting to run" % + (self.name, getattr(settings, 'SCHEDULE_MAX_JOBS', 10))) + return True return False def _can_update(self): diff --git a/awx/settings/defaults.py b/awx/settings/defaults.py index 6992983639..47a756b97b 100644 --- a/awx/settings/defaults.py +++ b/awx/settings/defaults.py @@ -96,6 +96,9 @@ JOBOUTPUT_ROOT = os.path.join(BASE_DIR, 'job_output') # The heartbeat file for the tower scheduler SCHEDULE_METADATA_LOCATION = os.path.join(BASE_DIR, '.tower_cycle') +# Maximum number of the same job that can be waiting to run when launching from scheduler +SCHEDULE_MAX_JOBS = 10 + SITE_ID = 1 # Make this unique, and don't share it with anybody.