From 820dcc32976b79c847982352331a8ecf37d760e7 Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Thu, 26 Sep 2024 17:10:03 +0200 Subject: [PATCH] Wrap scheduler to tolerate somehow invalid dispatches Signed-off-by: Mathias L. Baumann --- src/frequenz/dispatch/actor.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/frequenz/dispatch/actor.py b/src/frequenz/dispatch/actor.py index bb47e77..9befa08 100644 --- a/src/frequenz/dispatch/actor.py +++ b/src/frequenz/dispatch/actor.py @@ -71,6 +71,8 @@ def __init__( async def _run(self) -> None: """Run the actor.""" + _logger.info("Starting dispatch actor for microgrid %s", self._microgrid_id) + # Initial fetch await self._fetch() @@ -272,11 +274,16 @@ def _schedule_start(self, dispatch: Dispatch) -> None: return # Schedule the next run - if next_run := dispatch.next_run: - heappush(self._scheduled_events, (next_run, dispatch)) - _logger.debug("Scheduled dispatch %s to start at %s", dispatch.id, next_run) - else: - _logger.debug("Dispatch %s has no next run", dispatch.id) + try: + if next_run := dispatch.next_run: + heappush(self._scheduled_events, (next_run, dispatch)) + _logger.debug( + "Scheduled dispatch %s to start at %s", dispatch.id, next_run + ) + else: + _logger.debug("Dispatch %s has no next run", dispatch.id) + except ValueError as error: + _logger.error("Error scheduling dispatch %s: %s", dispatch.id, error) def _schedule_stop(self, dispatch: Dispatch) -> None: """Schedule a dispatch to stop.