Skip to content

Commit 9345acd

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 f65bed5 commit 9345acd

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
@@ -126,7 +126,6 @@ async def _run(self) -> None:
126126
self._dispatches.pop(dispatch.id)
127127
await self._update_dispatch_schedule_and_notify(None, dispatch)
128128

129-
dispatch._set_deleted() # pylint: disable=protected-access
130129
await self._lifecycle_updates_sender.send(
131130
Deleted(dispatch=dispatch)
132131
)
@@ -221,16 +220,18 @@ async def _update_dispatch_schedule_and_notify(
221220
if not dispatch and old_dispatch:
222221
self._remove_scheduled(old_dispatch)
223222

223+
was_running = old_dispatch.started
224+
old_dispatch._set_deleted() # pylint: disable=protected-access)
225+
224226
# If the dispatch was running, we need to notify
225-
if old_dispatch.started:
227+
if was_running:
226228
await self._send_running_state_change(old_dispatch)
227229

228230
# A new dispatch was created
229231
elif dispatch and not old_dispatch:
230232
assert not self._remove_scheduled(
231233
dispatch
232234
), "New dispatch already scheduled?!"
233-
234235
# If its currently running, send notification right away
235236
if dispatch.started:
236237
await self._send_running_state_change(dispatch)

0 commit comments

Comments
 (0)