8 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
996596ddc0
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>
2025-09-29 16:58:38 +03:00
Sunil Mohan Adapa
c96c97166f
glib: Change API for repeating an in-thread scheduled task
Previously, in glib.schedule(), when in_thread is set to True, it is expected
that the task method return whether it wants to be repeated (True) or
not (False). However, this was not documented and different from the behavior of
the separate-thread task (passed as argument repeat=). To simply and improve
consistency, use the repeat= argument instead of return value from the method.

This fixes issue with daily diagnostics not running for the second time.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2024-01-23 11:40:57 -08:00
Sunil Mohan Adapa
16c556de45
glib: Add a jitter to the interval by default when scheduling tasks
- When many tasks are scheduled at once, they will try to write to the database
at the same time. This happens prominently in develop mode when multiple
notifications are attempted to be shown.

- Also other resource contention may happen.

- Avoid this by adding or subtracting 5% to the provided task scheduling
interval time.

Tests:

- Print the interval times in the schedule() method and verify that the final
interval values are randomized and vary by only 5% from the provided interval.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-10-21 18:43:23 -04:00
Sunil Mohan Adapa
2bf4271e04
glib: Refactor schedule debugging in a central place
Tests:

- Print the interval time in schedule() method and verify that the times are as
expected in develop mode and production mode.

- Notification shows up for RAM usage if the check hardcoded to True.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2023-10-21 18:43:20 -04:00
Sunil Mohan Adapa
6216f7872c
glib: Allow scheduling non-repeating tasks in separate threads
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
2020-05-15 18:00:49 -07:00
Sunil Mohan Adapa
9368504da5
*.py: Use SPDX license identifier
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2020-02-19 14:38:55 +02:00
Sunil Mohan Adapa
9cf84286f4
glib: Introduce method to schedule an operation at regular intervals
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-10 18:12:58 -05:00
Sunil Mohan Adapa
2e534db168
glib: Create a new module to deal with all things glib
- Chmod -x dbus.py. It appears that the file was accidentally set to permissions
0o755 instead of 0o644.

glib module will contain:

- Code to deal with glib main loop.

- Use glib as a way to schedule timely events instead of creating long running
  threads.

- Other mechanisms to help with asynchronous I/O until we start using asyncio.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2020-02-10 18:12:55 -05:00