#19816: Capture additional logging under ScriptJob

This commit is contained in:
Jeremy Stretch 2025-08-13 15:19:39 -04:00
parent 4bd5b3574f
commit 72c552dd77

View File

@ -59,6 +59,7 @@ class ScriptJob(JobRunner):
else: else:
script.log_failure(msg) script.log_failure(msg)
logger.error(f"Script aborted with error: {e}") logger.error(f"Script aborted with error: {e}")
self.logger.error(f"Script aborted with error: {e}")
else: else:
stacktrace = traceback.format_exc() stacktrace = traceback.format_exc()
@ -66,9 +67,11 @@ class ScriptJob(JobRunner):
message=_("An exception occurred: ") + f"`{type(e).__name__}: {e}`\n```\n{stacktrace}\n```" message=_("An exception occurred: ") + f"`{type(e).__name__}: {e}`\n```\n{stacktrace}\n```"
) )
logger.error(f"Exception raised during script execution: {e}") logger.error(f"Exception raised during script execution: {e}")
self.logger.error(f"Exception raised during script execution: {e}")
if type(e) is not AbortTransaction: if type(e) is not AbortTransaction:
script.log_info(message=_("Database changes have been reverted due to error.")) script.log_info(message=_("Database changes have been reverted due to error."))
self.logger.info("Database changes have been reverted due to error.")
# Clear all pending events. Job termination (including setting the status) is handled by the job framework. # Clear all pending events. Job termination (including setting the status) is handled by the job framework.
if request: if request:
@ -108,9 +111,11 @@ class ScriptJob(JobRunner):
# Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process # Execute the script. If commit is True, wrap it with the event_tracking context manager to ensure we process
# change logging, event rules, etc. # change logging, event rules, etc.
if commit: if commit:
self.logger.info("Executing script (commit enabled)")
with ExitStack() as stack: with ExitStack() as stack:
for request_processor in registry['request_processors']: for request_processor in registry['request_processors']:
stack.enter_context(request_processor(request)) stack.enter_context(request_processor(request))
self.run_script(script, request, data, commit) self.run_script(script, request, data, commit)
else: else:
self.logger.warning("Executing script (commit disabled)")
self.run_script(script, request, data, commit) self.run_script(script, request, data, commit)