From 8b9a8a33f4e4436c01f99473d42b90b33fb03b2f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 18 Mar 2024 21:00:51 -1000 Subject: [PATCH] Start live history/logbook with eager tasks (#113779) --- homeassistant/components/history/websocket_api.py | 5 +++-- homeassistant/components/logbook/websocket_api.py | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/history/websocket_api.py b/homeassistant/components/history/websocket_api.py index 1f1c5064c5ae3..6eb1fec3416db 100644 --- a/homeassistant/components/history/websocket_api.py +++ b/homeassistant/components/history/websocket_api.py @@ -36,6 +36,7 @@ async_track_state_change_event, ) from homeassistant.helpers.json import json_bytes +from homeassistant.util.async_ import create_eager_task import homeassistant.util.dt as dt_util from .const import EVENT_COALESCE_TIME, MAX_PENDING_HISTORY_STATES @@ -536,7 +537,7 @@ def _queue_or_cancel(event: Event) -> None: # Unsubscribe happened while sending historical states return - live_stream.task = asyncio.create_task( + live_stream.task = create_eager_task( _async_events_consumer( subscriptions_setup_complete_time, connection, @@ -546,7 +547,7 @@ def _queue_or_cancel(event: Event) -> None: ) ) - live_stream.wait_sync_task = asyncio.create_task( + live_stream.wait_sync_task = create_eager_task( get_instance(hass).async_block_till_done() ) await live_stream.wait_sync_task diff --git a/homeassistant/components/logbook/websocket_api.py b/homeassistant/components/logbook/websocket_api.py index 4e4732c0d0e11..6d976a50240ed 100644 --- a/homeassistant/components/logbook/websocket_api.py +++ b/homeassistant/components/logbook/websocket_api.py @@ -18,6 +18,7 @@ from homeassistant.core import CALLBACK_TYPE, Event, HomeAssistant, callback from homeassistant.helpers.event import async_track_point_in_utc_time from homeassistant.helpers.json import json_bytes +from homeassistant.util.async_ import create_eager_task import homeassistant.util.dt as dt_util from .const import DOMAIN @@ -395,7 +396,7 @@ def _queue_or_cancel(event: Event) -> None: # Unsubscribe happened while sending historical events return - live_stream.task = asyncio.create_task( + live_stream.task = create_eager_task( _async_events_consumer( subscriptions_setup_complete_time, connection, @@ -405,7 +406,7 @@ def _queue_or_cancel(event: Event) -> None: ) ) - live_stream.wait_sync_task = asyncio.create_task( + live_stream.wait_sync_task = create_eager_task( get_instance(hass).async_block_till_done() ) await live_stream.wait_sync_task