Allow configuring the update refresh window

This enables customizing the time of day within which periodic refresh occurs.

Previously docs said it happens between 12am-4am which is misleading,
because the code effectively allowed refresh until 4:59:59 AM.
The default window is now '0-5', which is practically the same as before.

The comment about checking every 24h hours has been fixed as well.
This hasn't been true since commit c4fa76f217

Signed-off-by: Kamil Domański <kamil@domanski.co>
This commit is contained in:
Kamil Domański 2024-02-13 20:57:40 +01:00 committed by Eric Callahan
parent 65a8271925
commit 04b1103778
2 changed files with 29 additions and 7 deletions

View File

@ -1746,11 +1746,15 @@ disk or cloned from unofficial sources are not supported.
[update_manager] [update_manager]
enable_auto_refresh: False enable_auto_refresh: False
# When set to True Moonraker will attempt to fetch status about # When set to True, Moonraker will check roughly every 1 hour (only within
# available updates roughly every 24 hours, between 12am-4am. # the update window) whether it's time to fetch status about available updates.
# When set to False Moonraker will only fetch update state on startup # When set to False Moonraker will only fetch update state on startup
# and clients will need to request that Moonraker updates state. The # and clients will need to request that Moonraker updates state. The
# default is False. # default is False.
refresh_window: 0-5
# The hours between which the periodic update check will be done.
# Default is 0-5, meaning the refresh can only occur from midnight until 5am.
# It can go over midnight, e.g. 22-6.
refresh_interval: 672 refresh_interval: 672
# The interval (in hours) after which the update manager will check # The interval (in hours) after which the update manager will check
# for new updates. This interval is applies to updates for Moonraker, # for new updates. This interval is applies to updates for Moonraker,

View File

@ -48,8 +48,6 @@ if TYPE_CHECKING:
# Check To see if Updates are necessary each hour # Check To see if Updates are necessary each hour
UPDATE_REFRESH_INTERVAL = 3600. UPDATE_REFRESH_INTERVAL = 3600.
# Perform auto refresh no later than 4am
MAX_UPDATE_HOUR = 4
def get_deploy_class( def get_deploy_class(
app_type: Union[AppType, str], default: _T app_type: Union[AppType, str], default: _T
@ -69,7 +67,20 @@ class UpdateManager:
self.kconn: KlippyConnection self.kconn: KlippyConnection
self.kconn = self.server.lookup_component("klippy_connection") self.kconn = self.server.lookup_component("klippy_connection")
self.app_config = get_base_configuration(config) self.app_config = get_base_configuration(config)
auto_refresh_enabled = config.getboolean('enable_auto_refresh', False) auto_refresh_enabled = config.getboolean('enable_auto_refresh', False)
self.refresh_window = config.getintlist('refresh_window', [0, 5],
separator='-', count=2)
if (
not (0 <= self.refresh_window[0] <= 23) or
not (0 <= self.refresh_window[1] <= 23)
):
raise config.error("The hours specified in 'refresh_window'"
" must be between 0 and 23.")
if self.refresh_window[0] == self.refresh_window[1]:
raise config.error("The start and end hours specified"
" in 'refresh_window' cannot be the same.")
self.cmd_helper = CommandHelper(config, self.get_updaters) self.cmd_helper = CommandHelper(config, self.get_updaters)
self.updaters: Dict[str, BaseDeploy] = {} self.updaters: Dict[str, BaseDeploy] = {}
if config.getboolean('enable_system_updates', True): if config.getboolean('enable_system_updates', True):
@ -224,13 +235,20 @@ class UpdateManager:
if notify: if notify:
self.cmd_helper.notify_update_refreshed() self.cmd_helper.notify_update_refreshed()
async def _handle_auto_refresh(self, eventtime: float) -> float: def _is_within_refresh_window(self) -> bool:
cur_hour = time.localtime(time.time()).tm_hour cur_hour = time.localtime(time.time()).tm_hour
if self.refresh_window[0] < self.refresh_window[1]:
return self.refresh_window[0] <= cur_hour < self.refresh_window[1]
return cur_hour >= self.refresh_window[0] or cur_hour < self.refresh_window[1]
async def _handle_auto_refresh(self, eventtime: float) -> float:
log_remaining_time = True log_remaining_time = True
if self.initial_refresh_complete: if self.initial_refresh_complete:
log_remaining_time = False log_remaining_time = False
# Update when the local time is between 12AM and 5AM # Update only if within the refresh window
if cur_hour >= MAX_UPDATE_HOUR: if not self._is_within_refresh_window():
logging.debug("update_manager: current time is outside of"
" the refresh window, auto refresh rescheduled")
return eventtime + UPDATE_REFRESH_INTERVAL return eventtime + UPDATE_REFRESH_INTERVAL
if self.kconn.is_printing(): if self.kconn.is_printing():
# Don't Refresh during a print # Don't Refresh during a print