mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-29 07:21:27 +00:00
refactor: Return last 10 log lines when system rebuild failed
This commit is contained in:
parent
c733cfeb9e
commit
f895f2a38b
|
@ -43,10 +43,11 @@ def check_running_status(job: Job, unit_name: str):
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
if status == ServiceStatus.FAILED:
|
if status == ServiceStatus.FAILED:
|
||||||
|
log_lines = get_last_log_lines(unit_name, 10)
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job=job,
|
job=job,
|
||||||
status=JobStatus.ERROR,
|
status=JobStatus.ERROR,
|
||||||
error="System rebuild failed.",
|
error="System rebuild failed. Last log lines:\n" + "\n".join(log_lines),
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
if status == ServiceStatus.ACTIVE:
|
if status == ServiceStatus.ACTIVE:
|
||||||
|
@ -87,10 +88,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False):
|
||||||
interval=START_INTERVAL,
|
interval=START_INTERVAL,
|
||||||
)
|
)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
|
log_lines = get_last_log_lines(unit_name, 10)
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job=job,
|
job=job,
|
||||||
status=JobStatus.ERROR,
|
status=JobStatus.ERROR,
|
||||||
error="System rebuild timed out.",
|
error="System rebuild timed out. Last log lines:\n"
|
||||||
|
+ "\n".join(log_lines),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
|
@ -106,10 +109,12 @@ def rebuild_system_task(job: Job, upgrade: bool = False):
|
||||||
interval=RUN_INTERVAL,
|
interval=RUN_INTERVAL,
|
||||||
)
|
)
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
|
log_lines = get_last_log_lines(unit_name, 10)
|
||||||
Jobs.update(
|
Jobs.update(
|
||||||
job=job,
|
job=job,
|
||||||
status=JobStatus.ERROR,
|
status=JobStatus.ERROR,
|
||||||
error="System rebuild timed out.",
|
error="System rebuild timed out. Last log lines:\n"
|
||||||
|
+ "\n".join(log_lines),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,10 @@ def test_graphql_system_rebuild_failed(
|
||||||
|
|
||||||
fp.register(["systemctl", "show", unit_name], stdout="ActiveState=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(
|
response = authorized_client.post(
|
||||||
"/graphql",
|
"/graphql",
|
||||||
json={
|
json={
|
||||||
|
|
Loading…
Reference in a new issue