refactor: Return last 10 log lines when system rebuild failed
continuous-integration/drone/push Build is failing Details

pull/98/head
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={