Skip to content

Commit be524ad

Browse files
committed
Mark dispatch as deleted only in the update function.
This makes the code cleaner. Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent d5a391f commit be524ad

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/frequenz/dispatch/actor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ async def _run(self) -> None:
143143
self._dispatches.pop(dispatch.id)
144144
await self._update_dispatch_schedule_and_notify(None, dispatch)
145145

146-
dispatch._set_deleted() # pylint: disable=protected-access
147146
await self._lifecycle_updates_sender.send(
148147
Deleted(dispatch=dispatch)
149148
)
@@ -238,16 +237,18 @@ async def _update_dispatch_schedule_and_notify(
238237
if not dispatch and old_dispatch:
239238
self._remove_scheduled(old_dispatch)
240239

240+
was_running = old_dispatch.started
241+
old_dispatch._set_deleted() # pylint: disable=protected-access)
242+
241243
# If the dispatch was running, we need to notify
242-
if old_dispatch.started:
244+
if was_running:
243245
await self._send_running_state_change(old_dispatch)
244246

245247
# A new dispatch was created
246248
elif dispatch and not old_dispatch:
247249
assert not self._remove_scheduled(
248250
dispatch
249251
), "New dispatch already scheduled?!"
250-
251252
# If its currently running, send notification right away
252253
if dispatch.started:
253254
await self._send_running_state_change(dispatch)

0 commit comments

Comments
 (0)