Skip to content

Commit c0b9494

Browse files
committed
Add method to check if a type is currently being dispatched
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent c9c1181 commit c0b9494

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ This release introduces a more flexible and powerful mechanism for managing disp
2121

2222
* A new feature "merge strategy" (`MergeByType`, `MergeByTypeTarget`) has been added to the `Dispatcher.new_running_state_event_receiver` method. Using it, you can automatically merge consecutive and overlapping dispatch start/stop events of the same type. E.g. dispatch `A` starting at 10:10 and ending at 10:30 and dispatch `B` starts at 10:30 until 11:00, with the feature enabled this would in total trigger one start event, one reconfigure event at 10:30 and one stop event at 11:00.
2323
* The SDK dependency was widened to allow versions up to (excluding) v1.0.0-rc1600.
24-
* Actor management with dispatches has been simplified. Calling `Dispatcher.start_dispatching(dispatch_type, actor_factory, merge_strategy)` will begin managing your actor for the given type and merge strategy. All you need provide is an actor factory. To stop dispatching for your type, call `Dispatcher.stop_dispatching(dispatch_type)`.
24+
* Actor management with dispatches has been simplified:
25+
* `Dispatcher.start_dispatching(dispatch_type, actor_factory, merge_strategy)` to manage your actor for the given type and merge strategy. All you need provide is an actor factory.
26+
* `Dispatcher.stop_dispatching(dispatch_type)` to stop dispatching for the given type.
27+
* `Dispatcher.is_dispatching(dispatch_type)` to check if dispatching is active for the given type.

src/frequenz/dispatch/_dispatcher.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,17 @@ def cancel(self, msg: str | None = None) -> None:
221221
for instance in self._actor_dispatchers.values():
222222
instance.cancel()
223223

224+
def is_dispatching(self, dispatch_type: str) -> bool:
225+
"""Check if the dispatcher is managing actors for a given dispatch type.
226+
227+
Args:
228+
dispatch_type: The type of the dispatch to check.
229+
230+
Returns:
231+
True if the dispatcher is managing actors for the given dispatch type.
232+
"""
233+
return dispatch_type in self._actor_dispatchers
234+
224235
async def start_dispatching(
225236
self,
226237
dispatch_type: str,

0 commit comments

Comments
 (0)