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 11
11
## New Features
12
12
13
13
* 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
14
15
15
16
## Bug Fixes
16
17
Original file line number Diff line number Diff line change 8
8
9
9
import grpc .aio
10
10
from frequenz .channels import Broadcast , Receiver
11
+ from frequenz .client .dispatch import Client
11
12
12
13
from ._dispatch import Dispatch
13
14
from ._event import DispatchEvent
@@ -123,10 +124,10 @@ def __init__(
123
124
self ._lifecycle_events_channel = Broadcast [DispatchEvent ](
124
125
name = "lifecycle_events"
125
126
)
127
+ self ._client = Client (grpc_channel , svc_addr )
126
128
self ._actor = DispatchingActor (
127
129
microgrid_id ,
128
- grpc_channel ,
129
- svc_addr ,
130
+ self ._client ,
130
131
self ._lifecycle_events_channel .new_sender (),
131
132
self ._running_state_channel .new_sender (),
132
133
)
@@ -135,6 +136,11 @@ async def start(self) -> None:
135
136
"""Start the actor."""
136
137
self ._actor .start ()
137
138
139
+ @property
140
+ def client (self ) -> Client :
141
+ """Return the client."""
142
+ return self ._client
143
+
138
144
@property
139
145
def lifecycle_events (self ) -> ReceiverFetcher [DispatchEvent ]:
140
146
"""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):
47
47
def __init__ (
48
48
self ,
49
49
microgrid_id : int ,
50
- grpc_channel : grpc .aio .Channel ,
51
- svc_addr : str ,
50
+ client : Client ,
52
51
lifecycle_updates_sender : Sender [DispatchEvent ],
53
52
running_state_change_sender : Sender [Dispatch ],
54
53
poll_interval : timedelta = _DEFAULT_POLL_INTERVAL ,
@@ -57,15 +56,14 @@ def __init__(
57
56
58
57
Args:
59
58
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.
62
60
lifecycle_updates_sender: A sender for dispatch lifecycle events.
63
61
running_state_change_sender: A sender for dispatch running state changes.
64
62
poll_interval: The interval to poll the API for dispatche changes.
65
63
"""
66
64
super ().__init__ (name = "dispatch" )
67
65
68
- self ._client = Client ( grpc_channel , svc_addr )
66
+ self ._client = client
69
67
self ._dispatches : dict [int , Dispatch ] = {}
70
68
self ._scheduled : dict [int , asyncio .Task [None ]] = {}
71
69
self ._microgrid_id = microgrid_id
Original file line number Diff line number Diff line change 8
8
from datetime import datetime , timedelta , timezone
9
9
from random import randint
10
10
from typing import AsyncIterator , Iterator
11
- from unittest .mock import MagicMock
12
11
13
12
import async_solipsism
14
13
import time_machine
@@ -66,18 +65,15 @@ async def actor_env() -> AsyncIterator[ActorTestEnv]:
66
65
lifecycle_updates_dispatches = Broadcast [DispatchEvent ](name = "lifecycle_updates" )
67
66
running_state_change_dispatches = Broadcast [Dispatch ](name = "running_state_change" )
68
67
microgrid_id = randint (1 , 100 )
68
+ client = FakeClient ()
69
69
70
70
actor = DispatchingActor (
71
71
microgrid_id = microgrid_id ,
72
- grpc_channel = MagicMock (),
73
- svc_addr = "localhost" ,
74
72
lifecycle_updates_sender = lifecycle_updates_dispatches .new_sender (),
75
73
running_state_change_sender = running_state_change_dispatches .new_sender (),
74
+ client = client ,
76
75
)
77
76
78
- client = FakeClient ()
79
- actor ._client = client # pylint: disable=protected-access
80
-
81
77
actor .start ()
82
78
83
79
yield ActorTestEnv (
You can’t perform that action at this time.
0 commit comments