Cache failed Portainer image checks until the next watcher run (#195796)

This commit is contained in:
Robert Chmielowiec
2026-12-01 14:33:20 +01:00
committed by GitHub
parent 8f73124cd5
commit 1fc569c86d
2 changed files with 22 additions and 2 deletions
@@ -265,7 +265,7 @@ class PortainerCoordinator(
tuple[int, str], tuple[float, LocalImageInformation]
] = {}
self._image_status_cache: dict[
tuple[int, str], tuple[float, PortainerImageUpdateStatus]
tuple[int, str], tuple[float, PortainerImageUpdateStatus | None]
] = {}
self._event_listeners: dict[int, PortainerEventListener] = {}
self._event_listeners_enabled = False
@@ -721,7 +721,8 @@ class PortainerCoordinator(
endpoint_id,
err,
)
return None
# Cache the failure too, so it is retried with the watcher, not every poll
image_status = None
self._image_status_cache[cache_key] = (time.time(), image_status)
return image_status
+19
View File
@@ -650,6 +650,25 @@ async def test_update_recreated_container_check_fails(
assert state is not None
assert state.state == STATE_UNKNOWN
# Next scan interval to check if the cached failure is still in effect
freezer.tick(DEFAULT_SCAN_INTERVAL)
async_fire_time_changed(hass, dt_util.utcnow())
await hass.async_block_till_done(wait_background_tasks=True)
mock_portainer_client.container_image_status.assert_called_once()
# A new watcher run invalidates the cached failure
mock_portainer_watcher.last_check = dt_util.utcnow().timestamp()
freezer.tick(DEFAULT_SCAN_INTERVAL)
async_fire_time_changed(hass, dt_util.utcnow())
await hass.async_block_till_done(wait_background_tasks=True)
assert mock_portainer_client.container_image_status.call_count == 2
state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == STATE_UNKNOWN
async def test_server_update_up_to_date(
hass: HomeAssistant,