refactor: Return last 10 log lines when system rebuild failed

This commit is contained in:
Inex Code 2024-03-06 18:33:55 +03:00
parent c733cfeb9e
commit f895f2a38b
2 changed files with 12 additions and 3 deletions

View file

@ -43,10 +43,11 @@ def check_running_status(job: Job, unit_name: str):
)
return True
if status == ServiceStatus.FAILED:
log_lines = get_last_log_lines(unit_name, 10)
Jobs.update(
job=job,
status=JobStatus.ERROR,
error="System rebuild failed.",
error="System rebuild failed. Last log lines:\n" + "\n".join(log_lines),
)
return True
if status == ServiceStatus.ACTIVE:
@ -87,10 +88,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False):
interval=START_INTERVAL,
)
except TimeoutError:
log_lines = get_last_log_lines(unit_name, 10)
Jobs.update(
job=job,
status=JobStatus.ERROR,
error="System rebuild timed out.",
error="System rebuild timed out. Last log lines:\n"
+ "\n".join(log_lines),
)
return
Jobs.update(
@ -106,10 +109,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False):
interval=RUN_INTERVAL,
)
except TimeoutError:
log_lines = get_last_log_lines(unit_name, 10)
Jobs.update(
job=job,
status=JobStatus.ERROR,
error="System rebuild timed out.",
error="System rebuild timed out. Last log lines:\n"
+ "\n".join(log_lines),
)
return

View file

@ -182,6 +182,10 @@ def test_graphql_system_rebuild_failed(
fp.register(["systemctl", "show", unit_name], stdout="ActiveState=failed")
fp.register(
["journalctl", "-u", unit_name, "-n", "10", "-o", "cat"], stdout="Some error"
)
response = authorized_client.post(
"/graphql",
json={