mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
diagnostics: Add option to toggle daily run
The option is stored in kvstore. If no value is set, it is assumed to be enabled. Tests: - Disable daily run. In development mode, diagnostic are not run after several minutes. - Enable daily run. In development mode, diagnostics are run after several minutes. Signed-off-by: James Valleroy <jvalleroy@mailbox.org> [sunil: Minor refactoring and update messages in UI] Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
1 parent
9c5491de7e
commit
d7907e0ef3
4 files changed
+56
-11
No files matched your search
@@ -68,7 +68,7 @@ class DiagnosticsApp(app_module.App):
|
||||
glib.schedule(3600, _warn_about_low_ram_space)
|
||||
|
||||
# Run diagnostics once a day
|
||||
glib.schedule(24 * 3600, start_diagnostics, in_thread=False)
|
||||
glib.schedule(24 * 3600, _daily_diagnostics_run, in_thread=False)
|
||||
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
@@ -246,6 +246,15 @@ def _warn_about_low_ram_space(request):
|
||||
actions=actions, data=data, group='admin')
|
||||
|
||||
|
||||
def _daily_diagnostics_run(data: None = None):
|
||||
"""Start daily run if enabled."""
|
||||
if is_daily_run_enabled():
|
||||
logger.info('Starting daily diagnostics run')
|
||||
start_diagnostics()
|
||||
else:
|
||||
logger.info('Skipping daily diagnostics run (disabled)')
|
||||
|
||||
|
||||
def start_diagnostics(data: None = None):
|
||||
"""Start full diagnostics as a background operation."""
|
||||
logger.info('Running full diagnostics')
|
||||
@@ -343,3 +352,13 @@ def get_results():
|
||||
results['results'][app_id]['name'] = app.info.name or app_id
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def is_daily_run_enabled() -> bool:
|
||||
"""Return whether daily run is enabled."""
|
||||
return kvstore.get_default('diagnostics_daily_run_enabled', True)
|
||||
|
||||
|
||||
def set_daily_run_enabled(enabled: bool):
|
||||
"""Enable or disable daily run."""
|
||||
kvstore.set('diagnostics_daily_run_enabled', enabled)
|
||||
Reference in new issue
Block a user