glib: Add schedule parameter for setting interval in develop mode

Tests:

- In development mode, diagnostics task runs after about 180 seconds (with
jitter).

- In production mode, diagnostics task does not run after 180 seconds.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2025-09-25 15:22:20 -07:00 committed by Veiko Aasa
parent 9c3776b03d
commit 996596ddc0
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -51,8 +51,13 @@ def _run():
def schedule(interval, method, data=None, in_thread=True, repeat=True,
add_jitter=True):
"""Schedule a recurring call to a method with fixed interval."""
add_jitter=True, develop_interval=None):
"""Schedule a recurring call to a method with fixed interval.
develop_interval is number of seconds to schedule the task after when
running in development mode. A value of 180 seconds assumed if the value is
set to None or 0.
"""
def _runner():
"""Run the target method and log and exceptions."""
@ -74,8 +79,8 @@ def schedule(interval, method, data=None, in_thread=True, repeat=True,
# When running in development mode, reduce the interval for tasks so that
# they are triggered quickly and frequently to facilitate debugging.
if cfg.develop and interval > 180:
interval = 180
if cfg.develop:
interval = min(interval, develop_interval or 180)
if add_jitter:
# Add or subtract 5% random jitter to given interval to avoid many