mirror of
https://github.com/ansible/awx.git
synced 2026-05-09 10:27:37 -02:30
Rename default timeout and remove runtime_flag.
This commit is contained in:
@@ -501,7 +501,7 @@ class BaseTask(Task):
|
|||||||
return OrderedDict()
|
return OrderedDict()
|
||||||
|
|
||||||
def run_pexpect(self, instance, args, cwd, env, passwords, stdout_handle,
|
def run_pexpect(self, instance, args, cwd, env, passwords, stdout_handle,
|
||||||
output_replacements=None, runtime_flags={}):
|
output_replacements=None, extra_update_fields={}):
|
||||||
'''
|
'''
|
||||||
Run the given command using pexpect to capture output and provide
|
Run the given command using pexpect to capture output and provide
|
||||||
passwords when requested.
|
passwords when requested.
|
||||||
@@ -517,7 +517,7 @@ 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_TIMEOUT', {})
|
global_timeout = getattr(settings, 'DEFAULT_JOB_TIMEOUTS', {})
|
||||||
cls_name = instance.__class__.__name__
|
cls_name = instance.__class__.__name__
|
||||||
if cls_name in global_timeout:
|
if cls_name in global_timeout:
|
||||||
local_timeout = getattr(instance, 'timeout', 0)
|
local_timeout = getattr(instance, 'timeout', 0)
|
||||||
@@ -526,8 +526,8 @@ class BaseTask(Task):
|
|||||||
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)
|
||||||
child.logfile_read = logfile
|
child.logfile_read = logfile
|
||||||
runtime_flags['canceled'] = False
|
canceled = False
|
||||||
runtime_flags['timed_out'] = False
|
timed_out = False
|
||||||
last_stdout_update = time.time()
|
last_stdout_update = time.time()
|
||||||
idle_timeout = self.get_idle_timeout()
|
idle_timeout = self.get_idle_timeout()
|
||||||
expect_list = []
|
expect_list = []
|
||||||
@@ -550,17 +550,18 @@ class BaseTask(Task):
|
|||||||
# Refresh model instance from the database (to check cancel flag).
|
# Refresh model instance from the database (to check cancel flag).
|
||||||
instance = self.update_model(instance.pk)
|
instance = self.update_model(instance.pk)
|
||||||
if instance.cancel_flag:
|
if instance.cancel_flag:
|
||||||
runtime_flags['canceled'] = True
|
canceled = True
|
||||||
elif job_timeout != 0 and (time.time() - job_start) > job_timeout:
|
elif job_timeout != 0 and (time.time() - job_start) > job_timeout:
|
||||||
runtime_flags['timed_out'] = True
|
timed_out = True
|
||||||
if any(list(runtime_flags.values())):
|
extra_update_fields['job_explanation'] = "Job terminated due to timeout"
|
||||||
self._handle_termination(instance, child, is_cancel=runtime_flags['canceled'])
|
if canceled or timed_out:
|
||||||
|
self._handle_termination(instance, child, is_cancel=canceled)
|
||||||
if idle_timeout and (time.time() - last_stdout_update) > idle_timeout:
|
if idle_timeout and (time.time() - last_stdout_update) > idle_timeout:
|
||||||
child.close(True)
|
child.close(True)
|
||||||
runtime_flags['canceled'] = True
|
canceled = True
|
||||||
if runtime_flags['canceled']:
|
if canceled:
|
||||||
return 'canceled', child.exitstatus
|
return 'canceled', child.exitstatus
|
||||||
elif child.exitstatus == 0 and not runtime_flags['timed_out']:
|
elif child.exitstatus == 0 and not timed_out:
|
||||||
return 'successful', child.exitstatus
|
return 'successful', child.exitstatus
|
||||||
else:
|
else:
|
||||||
return 'failed', child.exitstatus
|
return 'failed', child.exitstatus
|
||||||
@@ -620,7 +621,6 @@ class BaseTask(Task):
|
|||||||
instance.websocket_emit_status("running")
|
instance.websocket_emit_status("running")
|
||||||
status, rc, tb = 'error', None, ''
|
status, rc, tb = 'error', None, ''
|
||||||
output_replacements = []
|
output_replacements = []
|
||||||
runtime_flags = {}
|
|
||||||
extra_update_fields = {}
|
extra_update_fields = {}
|
||||||
try:
|
try:
|
||||||
self.pre_run_hook(instance, **kwargs)
|
self.pre_run_hook(instance, **kwargs)
|
||||||
@@ -666,7 +666,7 @@ class BaseTask(Task):
|
|||||||
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
instance = self.update_model(pk, job_args=json.dumps(safe_args),
|
||||||
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
job_cwd=cwd, job_env=safe_env, result_stdout_file=stdout_filename)
|
||||||
status, rc = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle,
|
status, rc = self.run_pexpect(instance, args, cwd, env, kwargs['passwords'], stdout_handle,
|
||||||
runtime_flags=runtime_flags)
|
extra_update_fields=extra_update_fields)
|
||||||
except Exception:
|
except Exception:
|
||||||
if status != 'canceled':
|
if status != 'canceled':
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
@@ -684,8 +684,6 @@ class BaseTask(Task):
|
|||||||
try:
|
try:
|
||||||
stdout_handle.flush()
|
stdout_handle.flush()
|
||||||
stdout_handle.close()
|
stdout_handle.close()
|
||||||
if runtime_flags.get('timed_out', False):
|
|
||||||
extra_update_fields['job_explanation'] = "Job terminated due to timeout"
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
instance = self.update_model(pk, status=status, result_traceback=tb,
|
instance = self.update_model(pk, status=status, result_traceback=tb,
|
||||||
|
|||||||
@@ -277,8 +277,8 @@ TEST_OPENSTACK_PROJECT = ''
|
|||||||
TEST_AZURE_USERNAME = ''
|
TEST_AZURE_USERNAME = ''
|
||||||
TEST_AZURE_KEY_DATA = ''
|
TEST_AZURE_KEY_DATA = ''
|
||||||
|
|
||||||
# Exemplary job timeout settings
|
# Exemplary global job timeout settings
|
||||||
# DEFAULT_TIMEOUT = {
|
# DEFAULT_JOB_TIMEOUTS = {
|
||||||
# 'Job': 10,
|
# 'Job': 10,
|
||||||
# 'InventoryUpdate': 15,
|
# 'InventoryUpdate': 15,
|
||||||
# 'ProjectUpdate': 20,
|
# 'ProjectUpdate': 20,
|
||||||
|
|||||||
Reference in New Issue
Block a user