From 80121fe9a798c7d349e8b784dfd24bf38928eb68 Mon Sep 17 00:00:00 2001 From: Steven Engelbert Date: Mon, 2 Dec 2024 15:23:39 -0500 Subject: [PATCH] Create function to validate current persist_logs state prior to updates, then set to true if it is false with sane minimum auto-off delay --- CHANGELOG.md | 4 ++++ amplipi/updater/asgi.py | 17 +++++++++++++++++ amplipi/updater/static/index.html | 5 +++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ce9c03ae..25defefbc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # AmpliPi Software Releases +## 0.4.6 +* System + * Automatically persist logs during (and for a short time after) updates + ## 0.4.5 * Web App * Ensure that abnormally-shaped album art is still horizontally centered diff --git a/amplipi/updater/asgi.py b/amplipi/updater/asgi.py index b96b7b5e2..1cf6cdd96 100644 --- a/amplipi/updater/asgi.py +++ b/amplipi/updater/asgi.py @@ -255,11 +255,27 @@ def save_upload_file(upload_file: UploadFile, destination: pathlib.Path) -> None upload_file.file.close() +def persist_logs_during_update(): + """Used during system updates to ensure persist logs is activated and has a minimum delay""" + persist_data = get_log_persist_state() + existing_persist = persist_data.persist_logs + existing_delay = persist_data.auto_off_delay + # If persist logs is already on and has a larger delay, keep that delay; otherwise ensure it has our sane minimum for support + if existing_persist and (existing_delay > 3 or existing_delay == 0): + data = Persist_Logs(persist_logs=True, auto_off_delay=existing_delay) + toggle_persist_logs(data=data) + else: + # Three days is an arbitrary number, picked to ensure the next few days of usage post-update are captured for support cases + data = Persist_Logs(persist_logs=True, auto_off_delay=3) + toggle_persist_logs(data=data) + + @router.post("/update/upload") async def start_upload(file: UploadFile = File(...)): """ Start a upload based update """ logger.info(file.filename) try: + persist_logs_during_update() # TODO: use a temp directory and pass it the installation os.makedirs('web/uploads', exist_ok=True) save_upload_file(file, pathlib.Path('web/uploads/update.tar.gz')) @@ -285,6 +301,7 @@ async def download_update(info: ReleaseInfo): """ Download the update """ logger.info(f'downloading update from: {info.url}') try: + persist_logs_during_update() os.makedirs('web/uploads', exist_ok=True) download(info.url, 'web/uploads/update.tar.gz') return 200 diff --git a/amplipi/updater/static/index.html b/amplipi/updater/static/index.html index 3412bd7f6..7dfbefef3 100644 --- a/amplipi/updater/static/index.html +++ b/amplipi/updater/static/index.html @@ -44,7 +44,7 @@

AmpliPi

Custom Update