Skip to content

Commit bc76d7e

Browse files
committed
fixup! Fix wrong running
1 parent 9c7478f commit bc76d7e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/frequenz/dispatch/_dispatch.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ def running(self, type_: str) -> RunningState:
119119

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

122-
# A dispatch without duration is always running once it started
123-
if self.duration is None:
124-
if self.start_time <= now:
125-
return RunningState.RUNNING
122+
if now < self.start_time:
126123
return RunningState.STOPPED
124+
# A dispatch without duration is always running once it started
125+
elif self.duration is None:
126+
return RunningState.RUNNING
127127

128128
if until := self._until(now):
129129
return RunningState.RUNNING if now < until else RunningState.STOPPED

src/frequenz/dispatch/actor.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ async def _execute_scheduled_event(self, dispatch: Dispatch) -> None:
130130
else:
131131
self._schedule_start(dispatch)
132132

133+
self._update_timer()
134+
133135
async def _fetch(self) -> None:
134136
"""Fetch all relevant dispatches using list.
135137
@@ -234,10 +236,14 @@ async def _update_dispatch_schedule_and_notify(
234236
self._schedule_start(dispatch)
235237

236238
# We modified the schedule, so we need to reset the timer
239+
self._update_timer()
240+
241+
def _update_timer(self) -> None:
242+
"""Update the timer to the next event."""
237243
if self._scheduled_events:
238-
_logger.debug("Next event scheduled at %s", self._scheduled_events[0][0])
239244
due_at: datetime = self._scheduled_events[0][0]
240245
self._next_event_timer.reset(interval=due_at - datetime.now(timezone.utc))
246+
_logger.debug("Next event scheduled at %s", self._scheduled_events[0][0])
241247

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

0 commit comments

Comments
 (0)