Skip to content

Commit bd75c0f

Browse files
committed
ActorDispatcher: Rename map_dispatch to dispatch_identity
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 2c29ab7 commit bd75c0f

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/frequenz/dispatch/_actor_dispatcher.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def main():
128128
managing_actor = ActorDispatcher(
129129
actor_factory=MyActor.new_with_dispatch,
130130
running_status_receiver=status_receiver,
131-
map_dispatch=lambda dispatch: dispatch.id,
131+
dispatch_identity=lambda d: d.id,
132132
)
133133
134134
await run(managing_actor)
@@ -139,18 +139,19 @@ def __init__(
139139
self,
140140
actor_factory: Callable[[DispatchInfo, Receiver[DispatchInfo]], Actor],
141141
running_status_receiver: Receiver[Dispatch],
142-
map_dispatch: Callable[[Dispatch], int],
142+
dispatch_identity: Callable[[Dispatch], int],
143143
) -> None:
144144
"""Initialize the dispatch handler.
145145
146146
Args:
147147
actor_factory: A callable that creates an actor with some initial dispatch
148148
information.
149149
running_status_receiver: The receiver for dispatch running status changes.
150-
map_dispatch: A function to identify to which actor a dispatch refers.
150+
dispatch_identity: A function to identify to which actor a dispatch refers.
151+
By default, it uses the dispatch ID.
151152
"""
152153
super().__init__()
153-
self._map_dispatch = map_dispatch
154+
self._dispatch_identity = dispatch_identity
154155
self._dispatch_rx = running_status_receiver
155156
self._actor_factory = actor_factory
156157
self._actors: dict[int, Actor] = {}
@@ -171,7 +172,7 @@ async def _start_actor(self, dispatch: Dispatch) -> None:
171172
options=dispatch.payload,
172173
)
173174

174-
actor: Actor | None = self._actors.get(self._map_dispatch(dispatch))
175+
actor: Actor | None = self._actors.get(self._dispatch_identity(dispatch))
175176

176177
if actor:
177178
sent_str = ""
@@ -189,7 +190,7 @@ async def _start_actor(self, dispatch: Dispatch) -> None:
189190
dispatch_update,
190191
self._updates_channel.new_receiver(limit=1, warn_on_overflow=False),
191192
)
192-
self._actors[self._map_dispatch(dispatch)] = actor
193+
self._actors[self._dispatch_identity(dispatch)] = actor
193194

194195
actor.start()
195196

@@ -200,7 +201,7 @@ async def _stop_actor(self, stopping_dispatch: Dispatch, msg: str) -> None:
200201
stopping_dispatch: The dispatch that is stopping the actor.
201202
msg: The message to be passed to the actors being stopped.
202203
"""
203-
if actor := self._actors.pop(self._map_dispatch(stopping_dispatch), None):
204+
if actor := self._actors.pop(self._dispatch_identity(stopping_dispatch), None):
204205
await actor.stop(msg)
205206
else:
206207
_logger.warning(

src/frequenz/dispatch/_dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def id_identity(dispatch: Dispatch) -> int:
225225
running_status_receiver=await self.new_running_state_event_receiver(
226226
dispatch_type, merge_strategy=merge_strategy
227227
),
228-
map_dispatch=(
228+
dispatch_identity=(
229229
id_identity if merge_strategy is None else merge_strategy.identity
230230
),
231231
)

tests/test_mananging_actor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ async def test_env() -> AsyncIterator[TestEnv]:
104104
actors_service = ActorDispatcher(
105105
actor_factory=MockActor,
106106
running_status_receiver=channel.new_receiver(),
107-
map_dispatch=lambda dispatch: dispatch.id,
107+
dispatch_identity=lambda dispatch: dispatch.id,
108108
)
109109

110110
actors_service.start()

0 commit comments

Comments
 (0)