From 5e20dcb6ca235f5ed0580763a3ca8e9b12d17176 Mon Sep 17 00:00:00 2001 From: Yanis Guenane Date: Tue, 5 Feb 2019 13:40:57 +0100 Subject: [PATCH] jt, wfjt: Ensure SCHEDULE_MAX_JOBS is accurately respect Currently SCHEDULE_MAX_JOBS+1 can be scheduled rather than SCHEDULE_MAX_JOBS. This is due to the fact that we using strictly greater rather than greater or equal. Imagine we set SCHEDULE_MAX_JOBS=1, current logic: * First time (count = 0), count < 1 -> proceed * Second time (count = 1), count =< 1 -> proceed * Third time (count = 2), count > 1 -> prevented Imagine we set SCHEDULE_MAX_JOBS=1, new logic: * First time (count = 0), count < 1 -> proceed * Second time (count = 1), count =< 1 -> prevented Signed-off-by: Yanis Guenane --- awx/main/models/jobs.py | 2 +- awx/main/models/workflow.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index f1bca25392..74cccb2fd5 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -451,7 +451,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, Resour @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): + 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 diff --git a/awx/main/models/workflow.py b/awx/main/models/workflow.py index c91a67e765..4e4f2a8dbb 100644 --- a/awx/main/models/workflow.py +++ b/awx/main/models/workflow.py @@ -408,7 +408,7 @@ class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTempl @property def cache_timeout_blocked(self): if WorkflowJob.objects.filter(workflow_job_template=self, - status__in=['pending', 'waiting', 'running']).count() > getattr(settings, 'SCHEDULE_MAX_JOBS', 10): + status__in=['pending', 'waiting', 'running']).count() >= getattr(settings, 'SCHEDULE_MAX_JOBS', 10): logger.error("Workflow 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