mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
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>
This commit is contained in:
parent
2795e2d994
commit
2bf4271e04
@ -9,6 +9,8 @@ import threading
|
||||
from plinth import dbus, network
|
||||
from plinth.utils import import_from_gi
|
||||
|
||||
from . import cfg
|
||||
|
||||
glib = import_from_gi('GLib', '2.0')
|
||||
|
||||
_thread = None
|
||||
@ -67,4 +69,9 @@ def schedule(interval, method, data=None, in_thread=True, repeat=True):
|
||||
thread.start()
|
||||
return repeat
|
||||
|
||||
# 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
|
||||
|
||||
glib.timeout_add(int(interval * 1000), _run_bare_or_thread, None)
|
||||
|
||||
@ -56,10 +56,8 @@ class BackupsApp(app_module.App):
|
||||
@staticmethod
|
||||
def post_init():
|
||||
"""Perform post initialization operations."""
|
||||
# Check every hour (every 3 minutes in debug mode) to perform scheduled
|
||||
# backups.
|
||||
interval = 180 if cfg.develop else 3600
|
||||
glib.schedule(interval, backup_by_schedule)
|
||||
# Check every hour to perform scheduled backups
|
||||
glib.schedule(3600, backup_by_schedule)
|
||||
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
|
||||
@ -13,7 +13,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django.utils.translation import gettext_noop
|
||||
|
||||
from plinth import app as app_module
|
||||
from plinth import cfg, daemon, glib, menu
|
||||
from plinth import daemon, glib, menu
|
||||
from plinth import operation as operation_module
|
||||
from plinth.modules.apache.components import diagnose_url_on_all
|
||||
from plinth.modules.backups.components import BackupRestore
|
||||
@ -63,12 +63,10 @@ class DiagnosticsApp(app_module.App):
|
||||
def post_init():
|
||||
"""Perform post initialization operations."""
|
||||
# Check periodically for low RAM space
|
||||
interval = 180 if cfg.develop else 3600
|
||||
glib.schedule(interval, _warn_about_low_ram_space)
|
||||
glib.schedule(3600, _warn_about_low_ram_space)
|
||||
|
||||
# Run diagnostics once a day
|
||||
interval = 180 if cfg.develop else 86400
|
||||
glib.schedule(interval, start_diagnostics, in_thread=False)
|
||||
glib.schedule(24 * 3600, start_diagnostics, in_thread=False)
|
||||
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
|
||||
@ -90,10 +90,8 @@ class DynamicDNSApp(app_module.App):
|
||||
for domain_name in config['domains']:
|
||||
notify_domain_added(domain_name)
|
||||
|
||||
# Check every 5 minutes (every 3 minutes in debug mode) to perform
|
||||
# dynamic DNS updates.
|
||||
interval = 180 if cfg.develop else 300
|
||||
glib.schedule(interval, update_dns)
|
||||
# Check every 5 minutes to perform dynamic DNS updates.
|
||||
glib.schedule(300, update_dns)
|
||||
|
||||
def setup(self, old_version):
|
||||
"""Install and configure the app."""
|
||||
|
||||
@ -62,9 +62,8 @@ class StorageApp(app_module.App):
|
||||
@staticmethod
|
||||
def post_init():
|
||||
"""Perform post initialization operations."""
|
||||
# Check every hour for low disk space, every 3 minutes in debug mode
|
||||
interval = 180 if cfg.develop else 3600
|
||||
glib.schedule(interval, warn_about_low_disk_space)
|
||||
# Check every hour for low disk space
|
||||
glib.schedule(3600, warn_about_low_disk_space)
|
||||
|
||||
# Schedule initialization of UDisks2 initialization
|
||||
glib.schedule(3, udisks2.init, repeat=False)
|
||||
|
||||
@ -95,16 +95,13 @@ class UpgradesApp(app_module.App):
|
||||
"""Perform post initialization operations."""
|
||||
self._show_new_release_notification()
|
||||
|
||||
# Check every day (every 3 minutes in debug mode):
|
||||
# - backports becomes available -> configure it if selected by user
|
||||
interval = 180 if cfg.develop else 24 * 3600
|
||||
glib.schedule(interval, setup_repositories)
|
||||
# Check every day if backports becomes available, then configure it if
|
||||
# selected by user.
|
||||
glib.schedule(24 * 3600, setup_repositories)
|
||||
|
||||
# Check every day (every 3 minutes in debug mode):
|
||||
# - new stable release becomes available -> perform dist-upgrade if
|
||||
# updates are enabled
|
||||
interval = 180 if cfg.develop else 24 * 3600
|
||||
glib.schedule(interval, check_dist_upgrade)
|
||||
# Check every day if new stable release becomes available, then perform
|
||||
# dist-upgrade if updates are enabled
|
||||
glib.schedule(24 * 3600, check_dist_upgrade)
|
||||
|
||||
def _show_new_release_notification(self):
|
||||
"""When upgraded to new release, show a notification."""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user