upgrades: Run distribution upgrade at around 06:00 everyday

- Instead of an arbitrary time decided by when FreedomBox service as started.

Tests:

- Add a log message before return statement. Set the system clock to 02:00 and
start service in debug mode. Wait for 3 minutes. The timer is triggered but
nothings happens.

- Set the system clock to 06:10 and start service in debug mode. Wait for 3
minutes and a distribution upgrade check is performed and a message is printed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2025-04-03 18:56:30 -07:00 committed by James Valleroy
parent e039f9f061
commit fecccd20a8
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808

View File

@ -43,6 +43,8 @@ BACKPORTS_REQUESTED_KEY = 'upgrades_backports_requested'
DIST_UPGRADE_ENABLED_KEY = 'upgrades_dist_upgrade_enabled'
DIST_UPGRADE_RUN_HOUR = 6 # 06:00 (morning)
PKG_HOLD_DIAG_CHECK_ID = 'upgrades-package-holds'
logger = logging.getLogger(__name__)
@ -100,9 +102,9 @@ class UpgradesApp(app_module.App):
# selected by user.
glib.schedule(24 * 3600, setup_repositories)
# Check every day if new stable release becomes available, then perform
# dist-upgrade if updates are enabled
glib.schedule(24 * 3600, check_dist_upgrade)
# Check every day if new stable release becomes available and if we
# waited enough, then perform dist-upgrade if updates are enabled.
glib.schedule(3600, check_dist_upgrade)
def _show_new_release_notification(self):
"""When upgraded to new release, show a notification."""
@ -214,6 +216,12 @@ def setup_repositories(_):
def check_dist_upgrade(_):
"""Check for upgrade to new stable release."""
# Run once a day at a desired hour even when triggered every hour. There is
# a small chance that this won't run in a given day.
now = datetime.datetime.now() # Local timezone
if now.hour != DIST_UPGRADE_RUN_HOUR:
return
if is_dist_upgrade_enabled():
status = distupgrade.get_status()
starting = status['next_action'] in ('continue', 'ready')