Skip to content

Commit 820dcc3

Browse files
committed
Wrap scheduler to tolerate somehow invalid dispatches
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
1 parent 0287a09 commit 820dcc3

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/frequenz/dispatch/actor.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def __init__(
7171

7272
async def _run(self) -> None:
7373
"""Run the actor."""
74+
_logger.info("Starting dispatch actor for microgrid %s", self._microgrid_id)
75+
7476
# Initial fetch
7577
await self._fetch()
7678

@@ -272,11 +274,16 @@ def _schedule_start(self, dispatch: Dispatch) -> None:
272274
return
273275

274276
# Schedule the next run
275-
if next_run := dispatch.next_run:
276-
heappush(self._scheduled_events, (next_run, dispatch))
277-
_logger.debug("Scheduled dispatch %s to start at %s", dispatch.id, next_run)
278-
else:
279-
_logger.debug("Dispatch %s has no next run", dispatch.id)
277+
try:
278+
if next_run := dispatch.next_run:
279+
heappush(self._scheduled_events, (next_run, dispatch))
280+
_logger.debug(
281+
"Scheduled dispatch %s to start at %s", dispatch.id, next_run
282+
)
283+
else:
284+
_logger.debug("Dispatch %s has no next run", dispatch.id)
285+
except ValueError as error:
286+
_logger.error("Error scheduling dispatch %s: %s", dispatch.id, error)
280287

281288
def _schedule_stop(self, dispatch: Dispatch) -> None:
282289
"""Schedule a dispatch to stop.

0 commit comments

Comments
 (0)