From 15a42eeee13d28b00793f8cfe98f2d30df19228e Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 27 Jan 2023 17:19:08 -0500 Subject: [PATCH] Consume job_explanation when given by ansible-runner Add extra formatting to error messages for clarity Fix nonblocking related tracebacks, add logging --- awx/main/tasks/callback.py | 7 ++++--- awx/main/tasks/receptor.py | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/awx/main/tasks/callback.py b/awx/main/tasks/callback.py index 28ca1f2eacab..dd172efd8391 100644 --- a/awx/main/tasks/callback.py +++ b/awx/main/tasks/callback.py @@ -208,9 +208,10 @@ def status_handler(self, status_data, runner_config): # We opened a connection just for that save, close it here now connections.close_all() elif status_data['status'] == 'error': - result_traceback = status_data.get('result_traceback', None) - if result_traceback: - self.delay_update(result_traceback=result_traceback) + for field_name in ('result_traceback', 'job_explanation'): + field_value = status_data.get(field_name, None) + if field_value: + self.delay_update(**{field_name: field_value}) def artifacts_handler(self, artifact_dir): self.artifacts_processed = True diff --git a/awx/main/tasks/receptor.py b/awx/main/tasks/receptor.py index d887c82e8b64..a4dbfc2b5222 100644 --- a/awx/main/tasks/receptor.py +++ b/awx/main/tasks/receptor.py @@ -431,16 +431,16 @@ def _run_internal(self, receptor_ctl): # massive, only ask for last 1000 bytes startpos = max(stdout_size - 1000, 0) resultsock, resultfile = receptor_ctl.get_work_results(self.unit_id, startpos=startpos, return_socket=True, return_sockfile=True) - resultsock.setblocking(False) # this makes resultfile reads non blocking lines = resultfile.readlines() receptor_output = b"".join(lines).decode() if receptor_output: - self.task.runner_callback.delay_update(result_traceback=receptor_output) + self.task.runner_callback.delay_update(result_traceback=f'Worker output:\n{receptor_output}') elif detail: - self.task.runner_callback.delay_update(result_traceback=detail) + self.task.runner_callback.delay_update(result_traceback=f'Receptor detail:\n{detail}') else: logger.warning(f'No result details or output from {self.task.instance.log_format}, status:\n{state_name}') except Exception: + logger.exception(f'Work results error from job id={self.task.instance.id} work_unit={self.task.instance.work_unit_id}') raise RuntimeError(detail) return res