Improve error handling in _run_rota_job to persist logs and results for better UI diagnostics
This commit is contained in:
@@ -120,11 +120,36 @@ def _run_rota_job(run_id: int, use_external_generator: bool = False, generate_bu
|
|||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
run.log = (run.log or "") + "\n" + tb
|
run.log = (run.log or "") + "\n" + tb
|
||||||
result["builder_error"] = str(exc)
|
result["builder_error"] = str(exc)
|
||||||
|
# Persist the log immediately so UI can show it even if
|
||||||
|
# the outer flow later marks the run failed.
|
||||||
|
try:
|
||||||
|
run.save(update_fields=["log"])
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
run.mark_finished(result=result)
|
run.mark_finished(result=result)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
tb = traceback.format_exc()
|
tb = traceback.format_exc()
|
||||||
|
# Ensure the traceback is persisted into the run log and result (if
|
||||||
|
# available) before marking the run failed so the UI can display the
|
||||||
|
# diagnostic information when viewing the run details.
|
||||||
|
try:
|
||||||
|
run.log = (run.log or "") + "\n" + tb
|
||||||
|
# If we have a partially constructed `result`, attach it so the
|
||||||
|
# failure page can show any captured stdout/stderr
|
||||||
|
try:
|
||||||
|
if 'result' in locals() and isinstance(result, dict):
|
||||||
|
run.result = result
|
||||||
|
run.save(update_fields=["log", "result"])
|
||||||
|
else:
|
||||||
|
run.save(update_fields=["log"])
|
||||||
|
except Exception:
|
||||||
|
# best-effort: ignore persistence errors here
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
# ignore log assignment errors and continue to mark failed
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
run.mark_failed(message=tb)
|
run.mark_failed(message=tb)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user