Skip to content

Commit

Permalink
Wrap scheduler to tolerate somehow invalid dispatches
Browse files Browse the repository at this point in the history
Signed-off-by: Mathias L. Baumann <mathias.baumann@frequenz.com>
Marenz committed Sep 30, 2024
1 parent 0287a09 commit 820dcc3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/frequenz/dispatch/actor.py
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 820dcc3

Please sign in to comment.