@@ -93,55 +93,57 @@ async def run():
93
93
94
94
status_receiver = dispatcher.running_status_change.new_receiver()
95
95
96
- dispatch_runner = DispatchManagingActor(
97
- actor= my_actor,
96
+ managing_actor = DispatchManagingActor(
97
+ actors=frozenset([ my_actor]) ,
98
98
dispatch_type="EXAMPLE",
99
99
running_status_receiver=status_receiver,
100
100
updates_sender=dispatch_updates_channel.new_sender(),
101
101
)
102
102
103
- await asyncio.gather(dispatcher.start(), dispatch_runner .start())
103
+ await asyncio.gather(dispatcher.start(), managing_actor .start())
104
104
```
105
105
"""
106
106
107
107
def __init__ (
108
108
self ,
109
- actor : Actor ,
109
+ actors : frozenset [ Actor ] ,
110
110
dispatch_type : str ,
111
111
running_status_receiver : Receiver [Dispatch ],
112
112
updates_sender : Sender [DispatchUpdate ] | None = None ,
113
113
) -> None :
114
114
"""Initialize the dispatch handler.
115
115
116
116
Args:
117
- actor : The actor to manage.
117
+ actors : The actors to manage.
118
118
dispatch_type: The type of dispatches to handle.
119
119
running_status_receiver: The receiver for dispatch running status changes.
120
120
updates_sender: The sender for dispatch events
121
121
"""
122
122
super ().__init__ ()
123
123
self ._dispatch_rx = running_status_receiver
124
- self ._actor = actor
124
+ self ._actors = actors
125
125
self ._dispatch_type = dispatch_type
126
126
self ._updates_sender = updates_sender
127
127
128
- def _start_actor (self ) -> None :
129
- """Start the actor."""
130
- if self ._actor .is_running :
131
- _logger .warning ("Actor %s is already running" , self ._actor .name )
132
- else :
133
- self ._actor .start ()
128
+ def _start_actors (self ) -> None :
129
+ """Start all actors."""
130
+ for actor in self ._actors :
131
+ if actor .is_running :
132
+ _logger .warning ("Actor %s is already running" , actor .name )
133
+ else :
134
+ actor .start ()
134
135
135
- async def _stop_actor (self , msg : str ) -> None :
136
- """Stop the actor .
136
+ async def _stop_actors (self , msg : str ) -> None :
137
+ """Stop all actors .
137
138
138
139
Args:
139
- msg: The message to be passed to the actor being stopped.
140
+ msg: The message to be passed to the actors being stopped.
140
141
"""
141
- if self ._actor .is_running :
142
- await self ._actor .stop (msg )
143
- else :
144
- _logger .warning ("Actor %s is not running" , self ._actor .name )
142
+ for actor in self ._actors :
143
+ if actor .is_running :
144
+ await actor .stop (msg )
145
+ else :
146
+ _logger .warning ("Actor %s is not running" , actor .name )
145
147
146
148
async def _run (self ) -> None :
147
149
"""Wait for dispatches and handle them."""
@@ -158,7 +160,7 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None:
158
160
match running :
159
161
case RunningState .STOPPED :
160
162
_logger .info ("Stopped by dispatch %s" , dispatch .id )
161
- await self ._stop_actor ("Dispatch stopped" )
163
+ await self ._stop_actors ("Dispatch stopped" )
162
164
case RunningState .RUNNING :
163
165
if self ._updates_sender is not None :
164
166
_logger .info ("Updated by dispatch %s" , dispatch .id )
@@ -171,7 +173,7 @@ async def _handle_dispatch(self, dispatch: Dispatch) -> None:
171
173
)
172
174
173
175
_logger .info ("Started by dispatch %s" , dispatch .id )
174
- self ._start_actor ()
176
+ self ._start_actors ()
175
177
case RunningState .DIFFERENT_TYPE :
176
178
_logger .debug (
177
179
"Unknown dispatch! Ignoring dispatch of type %s" , dispatch .type
0 commit comments