mirror of
https://github.com/ansible/awx.git
synced 2024-10-30 22:21:13 +03:00
Merge pull request #3811 from AlanCoding/ctit_timeout_second_try
Move timeout settings into 3 different settings vars
This commit is contained in:
commit
eaca67af18
@ -175,19 +175,34 @@ register(
|
|||||||
)
|
)
|
||||||
|
|
||||||
register(
|
register(
|
||||||
'DEFAULT_JOB_TIMEOUTS',
|
'DEFAULT_JOB_TIMEOUT',
|
||||||
field_class=fields.DictField,
|
field_class=fields.IntegerField,
|
||||||
default={
|
min_value=0,
|
||||||
'Job': 0,
|
label=_('Default Job Timeout'),
|
||||||
'InventoryUpdate': 0,
|
help_text=_('Maximum time to allow jobs to run. Use value of 0 to indicate that no '
|
||||||
'ProjectUpdate': 0,
|
'timeout should be imposed. A timeout set on an individual job template will override this.'),
|
||||||
},
|
category=_('Jobs'),
|
||||||
label=_('Default Job Timeouts'),
|
category_slug='jobs',
|
||||||
help_text=_('Maximum time to allow jobs to run. Use sub-keys of Job, '
|
)
|
||||||
'InventoryUpdate, and ProjectUpdate to configure this value '
|
|
||||||
'for each job type. Use value of 0 to indicate that no '
|
register(
|
||||||
'timeout should be imposed. A timeout set on an individual '
|
'DEFAULT_INVENTORY_UPDATE_TIMEOUT',
|
||||||
'job template will override this.'),
|
field_class=fields.IntegerField,
|
||||||
|
min_value=0,
|
||||||
|
label=_('Default Inventory Update Timeout'),
|
||||||
|
help_text=_('Maximum time to allow inventory updates to run. Use value of 0 to indicate that no '
|
||||||
|
'timeout should be imposed. A timeout set on an individual inventory source will override this.'),
|
||||||
|
category=_('Jobs'),
|
||||||
|
category_slug='jobs',
|
||||||
|
)
|
||||||
|
|
||||||
|
register(
|
||||||
|
'DEFAULT_PROJECT_UPDATE_TIMEOUT',
|
||||||
|
field_class=fields.IntegerField,
|
||||||
|
min_value=0,
|
||||||
|
label=_('Default Project Update Timeout'),
|
||||||
|
help_text=_('Maximum time to allow project updates to run. Use value of 0 to indicate that no '
|
||||||
|
'timeout should be imposed. A timeout set on an individual project will override this.'),
|
||||||
category=_('Jobs'),
|
category=_('Jobs'),
|
||||||
category_slug='jobs',
|
category_slug='jobs',
|
||||||
)
|
)
|
||||||
|
@ -1226,6 +1226,9 @@ class InventoryUpdate(UnifiedJob, InventorySourceOptions, JobNotificationMixin):
|
|||||||
from awx.main.tasks import RunInventoryUpdate
|
from awx.main.tasks import RunInventoryUpdate
|
||||||
return RunInventoryUpdate
|
return RunInventoryUpdate
|
||||||
|
|
||||||
|
def _global_timeout_setting(self):
|
||||||
|
return 'DEFAULT_INVENTORY_UPDATE_TIMEOUT'
|
||||||
|
|
||||||
def websocket_emit_data(self):
|
def websocket_emit_data(self):
|
||||||
if self.inventory_source.group is not None:
|
if self.inventory_source.group is not None:
|
||||||
return dict(group_id=self.inventory_source.group.id)
|
return dict(group_id=self.inventory_source.group.id)
|
||||||
|
@ -583,6 +583,9 @@ class Job(UnifiedJob, JobOptions, JobNotificationMixin):
|
|||||||
from awx.main.tasks import RunJob
|
from awx.main.tasks import RunJob
|
||||||
return RunJob
|
return RunJob
|
||||||
|
|
||||||
|
def _global_timeout_setting(self):
|
||||||
|
return 'DEFAULT_JOB_TIMEOUT'
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse('api:job_detail', args=(self.pk,))
|
return reverse('api:job_detail', args=(self.pk,))
|
||||||
|
|
||||||
|
@ -423,6 +423,18 @@ class ProjectUpdate(UnifiedJob, ProjectOptions, JobNotificationMixin):
|
|||||||
from awx.main.tasks import RunProjectUpdate
|
from awx.main.tasks import RunProjectUpdate
|
||||||
return RunProjectUpdate
|
return RunProjectUpdate
|
||||||
|
|
||||||
|
def _global_timeout_setting(self):
|
||||||
|
return 'DEFAULT_PROJECT_UPDATE_TIMEOUT'
|
||||||
|
|
||||||
|
def is_blocked_by(self, obj):
|
||||||
|
if type(obj) == ProjectUpdate:
|
||||||
|
if self.project == obj.project:
|
||||||
|
return True
|
||||||
|
if type(obj) == Job:
|
||||||
|
if self.project == obj.project:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def websocket_emit_data(self):
|
def websocket_emit_data(self):
|
||||||
return dict(project_id=self.project.id)
|
return dict(project_id=self.project.id)
|
||||||
|
|
||||||
|
@ -554,6 +554,10 @@ class UnifiedJob(PolymorphicModel, PasswordFieldsModel, CommonModelNameNotUnique
|
|||||||
def _get_parent_field_name(cls):
|
def _get_parent_field_name(cls):
|
||||||
return 'unified_job_template' # Override in subclasses.
|
return 'unified_job_template' # Override in subclasses.
|
||||||
|
|
||||||
|
def _global_timeout_setting(self):
|
||||||
|
"Override in child classes, None value indicates this is not configurable"
|
||||||
|
return None
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return u'%s-%s-%s' % (self.created, self.id, self.status)
|
return u'%s-%s-%s' % (self.created, self.id, self.status)
|
||||||
|
|
||||||
|
@ -508,11 +508,11 @@ class BaseTask(Task):
|
|||||||
if pexpect_sleep is not None:
|
if pexpect_sleep is not None:
|
||||||
logger.info("Suspending Job Execution for QA Work")
|
logger.info("Suspending Job Execution for QA Work")
|
||||||
time.sleep(pexpect_sleep)
|
time.sleep(pexpect_sleep)
|
||||||
global_timeout = getattr(settings, 'DEFAULT_JOB_TIMEOUTS', {})
|
global_timeout_setting_name = instance._global_timeout_setting()
|
||||||
cls_name = instance.__class__.__name__
|
if global_timeout_setting_name:
|
||||||
if cls_name in global_timeout:
|
global_timeout = getattr(settings, global_timeout_setting_name, 0)
|
||||||
local_timeout = getattr(instance, 'timeout', 0)
|
local_timeout = getattr(instance, 'timeout', 0)
|
||||||
job_timeout = global_timeout[cls_name] if local_timeout == 0 else local_timeout
|
job_timeout = global_timeout if local_timeout == 0 else local_timeout
|
||||||
else:
|
else:
|
||||||
job_timeout = 0
|
job_timeout = 0
|
||||||
child = pexpect.spawnu(args[0], args[1:], cwd=cwd, env=env)
|
child = pexpect.spawnu(args[0], args[1:], cwd=cwd, env=env)
|
||||||
|
@ -276,10 +276,3 @@ TEST_OPENSTACK_PROJECT = ''
|
|||||||
# Azure credentials.
|
# Azure credentials.
|
||||||
TEST_AZURE_USERNAME = ''
|
TEST_AZURE_USERNAME = ''
|
||||||
TEST_AZURE_KEY_DATA = ''
|
TEST_AZURE_KEY_DATA = ''
|
||||||
|
|
||||||
# Exemplary global job timeout settings
|
|
||||||
# DEFAULT_JOB_TIMEOUTS = {
|
|
||||||
# 'Job': 10,
|
|
||||||
# 'InventoryUpdate': 15,
|
|
||||||
# 'ProjectUpdate': 20,
|
|
||||||
# }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user