Skip to content

Commit 184507a

Browse files
committed
Harden stream/fetch sync for CREATED and UPDATED
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 1657e3a commit 184507a

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

src/frequenz/dispatch/_bg_service.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -283,19 +283,26 @@ def is_more_relevant(
283283
dispatch = Dispatch(selected.message.dispatch)
284284
match selected.message.event:
285285
case Event.CREATED:
286-
self._dispatches[dispatch.id] = dispatch
287-
await self._update_dispatch_schedule_and_notify(
288-
dispatch, None, next_event_timer
289-
)
286+
# Check if the dispatch already exists and
287+
# was updated. The CREATE event is late in
288+
# this case
289+
if is_more_relevant(dispatch):
290+
self._dispatches[dispatch.id] = dispatch
291+
await self._update_dispatch_schedule_and_notify(
292+
dispatch, None, next_event_timer
293+
)
290294
await self._lifecycle_events_tx.send(
291295
Created(dispatch=dispatch)
292296
)
293297
case Event.UPDATED:
294-
await self._update_dispatch_schedule_and_notify(
295-
dispatch,
296-
self._dispatches[dispatch.id],
297-
next_event_timer,
298-
)
298+
# We might receive update before we fetched
299+
# the entry, so don't rely on it existing
300+
if is_more_relevant(dispatch):
301+
await self._update_dispatch_schedule_and_notify(
302+
dispatch,
303+
self._dispatches.get(dispatch.id),
304+
next_event_timer,
305+
)
299306
self._dispatches[dispatch.id] = dispatch
300307
await self._lifecycle_events_tx.send(
301308
Updated(dispatch=dispatch)

0 commit comments

Comments
 (0)