Skip to content

Commit

Permalink
fixup! Fix wrong running
Browse files Browse the repository at this point in the history
  • Loading branch information
Marenz committed Sep 24, 2024
1 parent 9c7478f commit 7003801
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/frequenz/dispatch/_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ def running(self, type_: str) -> RunningState:

now = datetime.now(tz=timezone.utc)

if now < self.start_time:
return RunningState.STOPPED
# A dispatch without duration is always running once it started
if self.duration is None:
if self.start_time <= now:
return RunningState.RUNNING
return RunningState.STOPPED
return RunningState.RUNNING

if until := self._until(now):
return RunningState.RUNNING if now < until else RunningState.STOPPED
Expand Down
8 changes: 7 additions & 1 deletion src/frequenz/dispatch/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ async def _execute_scheduled_event(self, dispatch: Dispatch) -> None:
else:
self._schedule_start(dispatch)

self._update_timer()

async def _fetch(self) -> None:
"""Fetch all relevant dispatches using list.
Expand Down Expand Up @@ -234,10 +236,14 @@ async def _update_dispatch_schedule_and_notify(
self._schedule_start(dispatch)

# We modified the schedule, so we need to reset the timer
self._update_timer()

def _update_timer(self) -> None:
"""Update the timer to the next event."""
if self._scheduled_events:
_logger.debug("Next event scheduled at %s", self._scheduled_events[0][0])
due_at: datetime = self._scheduled_events[0][0]
self._next_event_timer.reset(interval=due_at - datetime.now(timezone.utc))
_logger.debug("Next event scheduled at %s", self._scheduled_events[0][0])

def _remove_scheduled(self, dispatch: Dispatch) -> bool:
"""Remove a dispatch from the scheduled events.
Expand Down

0 comments on commit 7003801

Please sign in to comment.