diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c47df5e..b260c25 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -9,6 +9,9 @@ * `ActorDispatcher.ActorAndChannel` is no longer frozen and has a new required `current_dispatch` field. Code that builds it directly will break; use `ActorDispatcher` itself instead. +* The minimum `frequenz-channels` version is now 1.13.0. +* The minimum `frequenz-core` version is now 1.6.0, and the minimum `typing-extensions` version is now 4.16.0. These versions are required by `frequenz-channels` 1.13.0 too. +* The internal timers now use `MonotonicTimer`, and channel shutdown uses `aclose`. These replace APIs that `frequenz-channels` v2 removes. The public dispatch API and behavior are unchanged. ## New Features diff --git a/mkdocs.yml b/mkdocs.yml index 92ff39a..24ff3a3 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -115,7 +115,7 @@ plugins: inventories: # See https://mkdocstrings.github.io/python/usage/#import for details - https://docs.python.org/3/objects.inv - - https://frequenz-floss.github.io/frequenz-channels-python/v1.6/objects.inv + - https://frequenz-floss.github.io/frequenz-channels-python/v1/objects.inv - https://frequenz-floss.github.io/frequenz-client-base-python/v0.11/objects.inv - https://frequenz-floss.github.io/frequenz-client-dispatch-python/v0.11/objects.inv - https://frequenz-floss.github.io/frequenz-sdk-python/v1.0-pre/objects.inv diff --git a/pyproject.toml b/pyproject.toml index be31a62..b18c8e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,16 +34,16 @@ classifiers = [ ] requires-python = ">= 3.11, < 4" dependencies = [ - "typing-extensions >= 4.13.0, < 5.0.0", + "typing-extensions >= 4.16.0, < 5.0.0", # Make sure to update the version for cross-referencing also in the # mkdocs.yml file when changing the version here (look for the config key # plugins.mkdocstrings.handlers.python.inventories) "frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2300", - "frequenz-channels >= 1.6.1, < 2.0.0", + "frequenz-channels >= 1.13.0, < 2.0.0", "frequenz-client-dispatch >= 0.11.3, < 2.0.0", "frequenz-client-base >= 0.11.0, < 0.12.0", "frequenz-client-common >= 0.3.8, < 0.5.0", - "frequenz-core >= 1.0.2, < 2.0.0", + "frequenz-core >= 1.6.0, < 2.0.0", "grpcio >= 1.80.0, < 2.0.0", ] dynamic = ["version"] diff --git a/src/frequenz/dispatch/_actor_dispatcher.py b/src/frequenz/dispatch/_actor_dispatcher.py index 6111bb6..9d700c1 100644 --- a/src/frequenz/dispatch/_actor_dispatcher.py +++ b/src/frequenz/dispatch/_actor_dispatcher.py @@ -19,7 +19,7 @@ from warnings import warn from frequenz.channels import Broadcast, Receiver, Sender, select -from frequenz.channels.timer import SkipMissedAndDrift, Timer +from frequenz.channels.timer import MonotonicTimer, SkipMissedAndDrift from frequenz.client.dispatch.types import DispatchId, TargetComponents from frequenz.core.id import BaseId from frequenz.sdk.actor import Actor, BackgroundService @@ -480,7 +480,7 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen self._continuation_accept_timeout = continuation_accept_timeout self._dispatch_rx = running_status_receiver - self._retry_timer_rx = Timer(retry_interval, SkipMissedAndDrift()) + self._retry_timer_rx = MonotonicTimer(retry_interval, SkipMissedAndDrift()) self._actor_factory = actor_factory self._actors: dict[DispatchActorId, ActorDispatcher.ActorStatus] = {} self._dispatch_status: dict[DispatchId, ActorDispatcher.DispatchStatus] = {} @@ -722,7 +722,7 @@ async def _discard_unresponsive_predecessor( """ del self._actors[predecessor_identity] await predecessor.actor.stop("continuation outcome unknown") - await predecessor.channel.close() + await predecessor.channel.aclose() async def _try_handover( self, dispatch: Dispatch @@ -847,7 +847,7 @@ async def _stop_actor( if actor_and_channel is not None: _logger.info("Stopping actor for dispatch type %r", stopping_dispatch.type) await actor_and_channel.actor.stop(msg) - await actor_and_channel.channel.close() + await actor_and_channel.channel.aclose() elif identity in self._recently_continued: # A continuation handover already moved this identity's actor # elsewhere (see `_continue_actor`); its own stop arriving here diff --git a/src/frequenz/dispatch/_bg_service.py b/src/frequenz/dispatch/_bg_service.py index acc8075..f60ccdb 100644 --- a/src/frequenz/dispatch/_bg_service.py +++ b/src/frequenz/dispatch/_bg_service.py @@ -18,7 +18,7 @@ import grpc.aio from frequenz.channels import Broadcast, Receiver, select, selected_from -from frequenz.channels.timer import SkipMissedAndResync, Timer +from frequenz.channels.timer import MonotonicTimer, SkipMissedAndResync from frequenz.client.base.streaming import ( StreamFatalError, StreamRetrying, @@ -272,7 +272,9 @@ async def _run(self) -> None: # pylint: disable=too-many-branches # Streaming updates with closing( - Timer(timedelta(seconds=100), SkipMissedAndResync(), auto_start=False) + MonotonicTimer( + timedelta(seconds=100), SkipMissedAndResync(), auto_start=False + ) ) as next_event_timer: # Initial fetch await self._fetch(next_event_timer) @@ -381,7 +383,9 @@ async def _run(self) -> None: # pylint: disable=too-many-branches case StreamFatalError(): pass - async def _execute_scheduled_event(self, dispatch: Dispatch, timer: Timer) -> None: + async def _execute_scheduled_event( + self, dispatch: Dispatch, timer: MonotonicTimer + ) -> None: """Execute a scheduled event and schedule the next one if any. Args: @@ -403,7 +407,7 @@ async def _execute_scheduled_event(self, dispatch: Dispatch, timer: Timer) -> No self._update_timer(timer) - async def _fetch(self, timer: Timer) -> None: + async def _fetch(self, timer: MonotonicTimer) -> None: """Fetch all relevant dispatches using list. This is used for the initial fetch and for re-fetching all dispatches @@ -487,7 +491,10 @@ async def _fetch(self, timer: Timer) -> None: self._initial_fetch_event.set() async def _update_dispatch_schedule_and_notify( - self, dispatch: Dispatch | None, old_dispatch: Dispatch | None, timer: Timer + self, + dispatch: Dispatch | None, + old_dispatch: Dispatch | None, + timer: MonotonicTimer, ) -> None: """Update the schedule for a dispatch. @@ -556,7 +563,7 @@ async def _update_dispatch_schedule_and_notify( # We modified the schedule, so we need to reset the timer self._update_timer(timer) - def _update_timer(self, timer: Timer) -> None: + def _update_timer(self, timer: MonotonicTimer) -> None: """Update the timer to the next event.""" if self._scheduled_events: due_at: datetime = self._scheduled_events[0].time @@ -567,11 +574,11 @@ def _update_timer(self, timer: Timer) -> None: # `QueueItem`'s own docstring on same-time start/stop ordering). # Once the first of the pair is processed, this recomputed # interval for the second can be exactly zero or slightly - # negative. `Timer.reset()` accepts that value without complaint, - # but a zero interval later crashes the timer's OWN drift + # negative. `MonotonicTimer.reset()` accepts that value without + # complaint, but a zero interval later crashes the timer's OWN drift # correction with a `ZeroDivisionError` in # `MissedTickPolicy.calculate_next_tick_time` (`drift % interval`). - # Floor it to the smallest positive interval `Timer` itself + # Floor it to the smallest positive interval `MonotonicTimer` itself # accepts, instead: the due event is already due, so it fires on # the very next tick either way, but doesn't poison the timer's # internal state. @@ -582,7 +589,7 @@ def _update_timer(self, timer: Timer) -> None: else: # With nothing queued, leave the timer running at its last # interval, which can be as small as the microsecond floor above. - # `Timer` is periodic, so it then keeps firing at that interval + # `MonotonicTimer` is periodic, so it then keeps firing at that interval # until a new dispatch event is scheduled -- potentially for # hours, burning CPU for no reason. Park it at a long interval # instead; the next call to `_update_timer()` (from whichever diff --git a/tests/test_continuation_realclock.py b/tests/test_continuation_realclock.py index eceefb2..6b9c4ef 100644 --- a/tests/test_continuation_realclock.py +++ b/tests/test_continuation_realclock.py @@ -7,7 +7,7 @@ asyncio event loop and genuine `datetime.now()`, with SHORT real dispatch durations (a few seconds), so the whole suite still runs in a few seconds while every clock involved -- `asyncio`'s own loop time and -`DispatchScheduler`'s `Timer` -- is the SAME, single, real clock. This +`DispatchScheduler`'s `MonotonicTimer` -- is the SAME, single, real clock. This exercises the real `Dispatcher.start_managing()`, the real `DispatchScheduler`, and the official `FakeClient` test double, end-to-end. See `test_continuation_handover.py` for the deterministic, millisecond-fast diff --git a/tests/test_dispatcher_scheduler.py b/tests/test_dispatcher_scheduler.py index a7db07d..0a1c7da 100644 --- a/tests/test_dispatcher_scheduler.py +++ b/tests/test_dispatcher_scheduler.py @@ -14,7 +14,7 @@ import async_solipsism import time_machine from frequenz.channels import Receiver -from frequenz.channels.timer import Timer +from frequenz.channels.timer import MonotonicTimer from frequenz.client.common.microgrid import MicrogridId from frequenz.client.dispatch.recurrence import RecurrenceRule from frequenz.client.dispatch.test.client import FakeClient, to_create_params @@ -68,7 +68,7 @@ def test_update_timer_floors_already_due_interval( stop_event=False, ) ) - timer = mocker.create_autospec(Timer, instance=True) + timer = mocker.create_autospec(MonotonicTimer, instance=True) scheduler._update_timer(timer) # pylint: disable=protected-access @@ -82,7 +82,7 @@ def test_update_timer_parks_timer_when_queue_is_empty( ) -> None: """Don't leave a tiny interval behind once no events are queued.""" scheduler = DispatchScheduler(microgrid_id=microgrid_id, client=client) - timer = mocker.create_autospec(Timer, instance=True) + timer = mocker.create_autospec(MonotonicTimer, instance=True) scheduler._update_timer(timer) # pylint: disable=protected-access diff --git a/tests/test_managing_actor.py b/tests/test_managing_actor.py index df76f25..ad151fc 100644 --- a/tests/test_managing_actor.py +++ b/tests/test_managing_actor.py @@ -169,7 +169,7 @@ async def actor_factory( if actor_and_channel is None: continue await actor_and_channel.actor.stop("Test finished") - await actor_and_channel.channel.close() + await actor_and_channel.channel.aclose() # pylint: enable=protected-access