Skip to content

Commit

Permalink
Rename DispatchUpdate to DispatchInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias L. Baumann <[email protected]>
  • Loading branch information
Marenz committed Feb 4, 2025
1 parent 850b044 commit dc0aee7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This release introduces a more flexible and powerful mechanism for managing disp
* It's interface has been simplified and now only requires an actor factory and a running status receiver.
* It only supports a single actor at a time now.
* Refer to the updated [usage example](https://frequenz-floss.github.io/frequenz-dispatch-python/latest/reference/frequenz/dispatch/#frequenz.dispatch.DispatchActorsService) for more information.
* `DispatchUpdate` was renamed to `DispatchInfo`.

## New Features

Expand Down
4 changes: 2 additions & 2 deletions src/frequenz/dispatch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""

from ._actor_dispatcher import ActorDispatcher, DispatchUpdate
from ._actor_dispatcher import ActorDispatcher, DispatchInfo
from ._dispatch import Dispatch
from ._dispatcher import Dispatcher
from ._event import Created, Deleted, DispatchEvent, Updated
Expand All @@ -28,5 +28,5 @@
"Updated",
"Dispatch",
"ActorDispatcher",
"DispatchUpdate",
"DispatchInfo",
]
20 changes: 10 additions & 10 deletions src/frequenz/dispatch/_actor_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@dataclass(frozen=True, kw_only=True)
class DispatchUpdate:
class DispatchInfo:
"""Event emitted when the dispatch changes."""

components: TargetComponents
Expand All @@ -41,7 +41,7 @@ class ActorDispatcher(BackgroundService):
import os
import asyncio
from typing import override
from frequenz.dispatch import Dispatcher, DispatchManagingActor, DispatchUpdate
from frequenz.dispatch import Dispatcher, DispatchManagingActor, DispatchInfo
from frequenz.client.dispatch.types import TargetComponents
from frequenz.client.common.microgrid.components import ComponentCategory
from frequenz.channels import Receiver, Broadcast, select, selected_from
Expand All @@ -54,15 +54,15 @@ def __init__(
name: str | None = None,
) -> None:
super().__init__(name=name)
self._dispatch_updates_receiver: Receiver[DispatchUpdate] | None = None
self._dispatch_updates_receiver: Receiver[DispatchInfo] | None = None
self._dry_run: bool = False
self._options: dict[str, Any] = {}
@classmethod
def new_with_dispatch(
cls,
initial_dispatch: DispatchUpdate,
dispatch_updates_receiver: Receiver[DispatchUpdate],
initial_dispatch: DispatchInfo,
dispatch_updates_receiver: Receiver[DispatchInfo],
*,
name: str | None = None,
) -> "Self":
Expand Down Expand Up @@ -92,7 +92,7 @@ async def _run_with_dispatch(self, other_recv: Receiver[Any]) -> None:
else:
assert False, f"Unexpected selected receiver: {selected}"
def _update_dispatch_information(self, dispatch_update: DispatchUpdate) -> None:
def _update_dispatch_information(self, dispatch_update: DispatchInfo) -> None:
print("Received update:", dispatch_update)
self._dry_run = dispatch_update.dry_run
self._options = dispatch_update.options
Expand Down Expand Up @@ -136,7 +136,7 @@ async def main():

def __init__(
self,
actor_factory: Callable[[DispatchUpdate, Receiver[DispatchUpdate]], Actor],
actor_factory: Callable[[DispatchInfo, Receiver[DispatchInfo]], Actor],
running_status_receiver: Receiver[Dispatch],
) -> None:
"""Initialize the dispatch handler.
Expand All @@ -150,7 +150,7 @@ def __init__(
self._dispatch_rx = running_status_receiver
self._actor_factory = actor_factory
self._actor: Actor | None = None
self._updates_channel = Broadcast[DispatchUpdate](
self._updates_channel = Broadcast[DispatchInfo](
name="dispatch_updates_channel", resend_latest=True
)
self._updates_sender = self._updates_channel.new_sender()
Expand All @@ -159,7 +159,7 @@ def start(self) -> None:
"""Start the background service."""
self._tasks.add(asyncio.create_task(self._run()))

def new_receiver(self) -> Receiver[DispatchUpdate]:
def new_receiver(self) -> Receiver[DispatchInfo]:
"""Create a new receiver for dispatch updates.
Returns:
Expand All @@ -169,7 +169,7 @@ def new_receiver(self) -> Receiver[DispatchUpdate]:

async def _start_actor(self, dispatch: Dispatch) -> None:
"""Start all actors."""
dispatch_update = DispatchUpdate(
dispatch_update = DispatchInfo(
components=dispatch.target,
dry_run=dispatch.dry_run,
options=dispatch.payload,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_mananging_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from frequenz.sdk.actor import Actor
from pytest import fixture

from frequenz.dispatch import ActorDispatcher, Dispatch, DispatchUpdate
from frequenz.dispatch import ActorDispatcher, Dispatch, DispatchInfo
from frequenz.dispatch._bg_service import DispatchScheduler


Expand Down Expand Up @@ -48,7 +48,7 @@ class MockActor(Actor):
"""Mock actor for testing."""

def __init__(
self, initial_dispatch: DispatchUpdate, receiver: Receiver[DispatchUpdate]
self, initial_dispatch: DispatchInfo, receiver: Receiver[DispatchInfo]
) -> None:
"""Initialize the actor."""
super().__init__(name="MockActor")
Expand Down Expand Up @@ -79,7 +79,7 @@ def actor(self) -> MockActor | None:
# pylint: enable=protected-access

@property
def updates_receiver(self) -> Receiver[DispatchUpdate]:
def updates_receiver(self) -> Receiver[DispatchInfo]:
"""Return the updates receiver."""
assert self.actor is not None
return self.actor.receiver
Expand Down Expand Up @@ -128,7 +128,7 @@ async def test_simple_start_stop(
),
)

# Send status update to start actor, expect no DispatchUpdate for the start
# Send status update to start actor, expect no DispatchInfo for the start
await test_env.running_status_sender.send(Dispatch(dispatch))
fake_time.shift(timedelta(seconds=1))
await asyncio.sleep(1)
Expand Down

0 comments on commit dc0aee7

Please sign in to comment.