From a22d815c883267d624db8446b04aaeb197d89bda Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Thu, 1 Dec 2016 12:03:43 -0500 Subject: [PATCH] Add ability to disable global job timeout. --- .../0053_v310_update_timeout_field_type.py | 44 +++++++++++++++++++ awx/main/models/inventory.py | 3 +- awx/main/models/jobs.py | 4 +- awx/main/models/projects.py | 2 +- awx/main/tasks.py | 5 ++- 5 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 awx/main/migrations/0053_v310_update_timeout_field_type.py diff --git a/awx/main/migrations/0053_v310_update_timeout_field_type.py b/awx/main/migrations/0053_v310_update_timeout_field_type.py new file mode 100644 index 0000000000..9365a4156a --- /dev/null +++ b/awx/main/migrations/0053_v310_update_timeout_field_type.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0052_v310_inventory_name_non_unique'), + ] + + operations = [ + migrations.AlterField( + model_name='inventorysource', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + migrations.AlterField( + model_name='inventoryupdate', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + migrations.AlterField( + model_name='job', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + migrations.AlterField( + model_name='jobtemplate', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + migrations.AlterField( + model_name='project', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + migrations.AlterField( + model_name='projectupdate', + name='timeout', + field=models.IntegerField(default=0, blank=True), + ), + ] diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index f8ca4abe1d..c16b89bcb2 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -859,7 +859,7 @@ class InventorySourceOptions(BaseModel): default=False, help_text=_('Overwrite local variables from remote inventory source.'), ) - timeout = models.PositiveIntegerField( + timeout = models.IntegerField( blank=True, default=0, ) @@ -1309,4 +1309,3 @@ class CustomInventoryScript(CommonModelNameNotUnique, ResourceMixin): def get_absolute_url(self): return reverse('api:inventory_script_detail', args=(self.pk,)) - diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index b5cf3bc307..96f1afba8d 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -148,9 +148,9 @@ class JobOptions(BaseModel): allow_simultaneous = models.BooleanField( default=False, ) - timeout = models.PositiveIntegerField( + timeout = models.IntegerField( blank=True, - default=0, + default=0, ) extra_vars_dict = VarsDictProperty('extra_vars', True) diff --git a/awx/main/models/projects.py b/awx/main/models/projects.py index a672ea4a7b..1b56ae72a3 100644 --- a/awx/main/models/projects.py +++ b/awx/main/models/projects.py @@ -106,7 +106,7 @@ class ProjectOptions(models.Model): default=None, on_delete=models.SET_NULL, ) - timeout = models.PositiveIntegerField( + timeout = models.IntegerField( blank=True, default=0, ) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 0c8aa8acce..69ee427c60 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -51,7 +51,7 @@ from awx.main.queue import CallbackQueueDispatcher from awx.main.task_engine import TaskEnhancer from awx.main.utils import (get_ansible_version, get_ssh_version, decrypt_field, update_scm_url, check_proot_installed, build_proot_temp_dir, wrap_args_with_proot, - get_system_task_capacity, OutputEventFilter) + get_system_task_capacity, OutputEventFilter) from awx.main.consumers import emit_channel_notification __all__ = ['RunJob', 'RunSystemJob', 'RunProjectUpdate', 'RunInventoryUpdate', @@ -524,6 +524,7 @@ class BaseTask(Task): global_timeout = getattr(settings, global_timeout_setting_name, 0) local_timeout = getattr(instance, 'timeout', 0) job_timeout = global_timeout if local_timeout == 0 else local_timeout + job_timeout = 0 if local_timeout < 0 else job_timeout else: job_timeout = 0 child = pexpect.spawnu(args[0], args[1:], cwd=cwd, env=env) @@ -986,7 +987,7 @@ class RunJob(BaseTask): Wrap stdout file object to capture events. ''' stdout_handle = super(RunJob, self).get_stdout_handle(instance) - + if getattr(settings, 'USE_CALLBACK_QUEUE', False): dispatcher = CallbackQueueDispatcher()