File tree Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Expand file tree Collapse file tree 4 files changed +14
-13
lines changed Original file line number Diff line number Diff line change 1111## New Features
1212
1313* Introduced new class ` Dispatch ` (based on the client class) that contains useful functions and extended information about the received dispatch.
14+ * ` Dispatcher.client ` was added to provide an easy access to the client for updating, deleting and creating dispatches
1415
1516## Bug Fixes
1617
Original file line number Diff line number Diff line change 88
99import grpc .aio
1010from frequenz .channels import Broadcast , Receiver
11+ from frequenz .client .dispatch import Client
1112
1213from ._dispatch import Dispatch
1314from ._event import DispatchEvent
@@ -123,10 +124,10 @@ def __init__(
123124 self ._lifecycle_events_channel = Broadcast [DispatchEvent ](
124125 name = "lifecycle_events"
125126 )
127+ self ._client = Client (grpc_channel , svc_addr )
126128 self ._actor = DispatchingActor (
127129 microgrid_id ,
128- grpc_channel ,
129- svc_addr ,
130+ self ._client ,
130131 self ._lifecycle_events_channel .new_sender (),
131132 self ._running_state_channel .new_sender (),
132133 )
@@ -135,6 +136,11 @@ async def start(self) -> None:
135136 """Start the actor."""
136137 self ._actor .start ()
137138
139+ @property
140+ def client (self ) -> Client :
141+ """Return the client."""
142+ return self ._client
143+
138144 @property
139145 def lifecycle_events (self ) -> ReceiverFetcher [DispatchEvent ]:
140146 """Return new, updated or deleted dispatches receiver fetcher.
Original file line number Diff line number Diff line change @@ -47,8 +47,7 @@ class DispatchingActor(Actor):
4747 def __init__ (
4848 self ,
4949 microgrid_id : int ,
50- grpc_channel : grpc .aio .Channel ,
51- svc_addr : str ,
50+ client : Client ,
5251 lifecycle_updates_sender : Sender [DispatchEvent ],
5352 running_state_change_sender : Sender [Dispatch ],
5453 poll_interval : timedelta = _DEFAULT_POLL_INTERVAL ,
@@ -57,15 +56,14 @@ def __init__(
5756
5857 Args:
5958 microgrid_id: The microgrid ID to handle dispatches for.
60- grpc_channel: The gRPC channel to use for communication with the API.
61- svc_addr: Address of the service to connect to.
59+ client: The client to use for fetching dispatches.
6260 lifecycle_updates_sender: A sender for dispatch lifecycle events.
6361 running_state_change_sender: A sender for dispatch running state changes.
6462 poll_interval: The interval to poll the API for dispatche changes.
6563 """
6664 super ().__init__ (name = "dispatch" )
6765
68- self ._client = Client ( grpc_channel , svc_addr )
66+ self ._client = client
6967 self ._dispatches : dict [int , Dispatch ] = {}
7068 self ._scheduled : dict [int , asyncio .Task [None ]] = {}
7169 self ._microgrid_id = microgrid_id
Original file line number Diff line number Diff line change 88from datetime import datetime , timedelta , timezone
99from random import randint
1010from typing import AsyncIterator , Iterator
11- from unittest .mock import MagicMock
1211
1312import async_solipsism
1413import time_machine
@@ -66,18 +65,15 @@ async def actor_env() -> AsyncIterator[ActorTestEnv]:
6665 lifecycle_updates_dispatches = Broadcast [DispatchEvent ](name = "lifecycle_updates" )
6766 running_state_change_dispatches = Broadcast [Dispatch ](name = "running_state_change" )
6867 microgrid_id = randint (1 , 100 )
68+ client = FakeClient ()
6969
7070 actor = DispatchingActor (
7171 microgrid_id = microgrid_id ,
72- grpc_channel = MagicMock (),
73- svc_addr = "localhost" ,
7472 lifecycle_updates_sender = lifecycle_updates_dispatches .new_sender (),
7573 running_state_change_sender = running_state_change_dispatches .new_sender (),
74+ client = client ,
7675 )
7776
78- client = FakeClient ()
79- actor ._client = client # pylint: disable=protected-access
80-
8177 actor .start ()
8278
8379 yield ActorTestEnv (
You can’t perform that action at this time.
0 commit comments