Skip to content

Commit f65bed5

Browse files
committed
Remove unused RunningState Sent tracking
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 5e2c123 commit f65bed5

File tree

3 files changed

+9
-47
lines changed

3 files changed

+9
-47
lines changed

src/frequenz/dispatch/_dispatch.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,20 @@ class Dispatch(BaseDispatch):
1717
deleted: bool = False
1818
"""Whether the dispatch is deleted."""
1919

20-
running_state_change_synced: datetime | None = None
21-
"""The last time a message was sent about the running state change."""
22-
2320
def __init__(
2421
self,
2522
client_dispatch: BaseDispatch,
2623
deleted: bool = False,
27-
running_state_change_synced: datetime | None = None,
2824
):
2925
"""Initialize the dispatch.
3026
3127
Args:
3228
client_dispatch: The client dispatch.
3329
deleted: Whether the dispatch is deleted.
34-
running_state_change_synced: Timestamp of the last running state change message.
3530
"""
3631
super().__init__(**client_dispatch.__dict__)
3732
# Work around frozen to set deleted
3833
object.__setattr__(self, "deleted", deleted)
39-
object.__setattr__(
40-
self,
41-
"running_state_change_synced",
42-
running_state_change_synced,
43-
)
4434

4535
def _set_deleted(self) -> None:
4636
"""Mark the dispatch as deleted."""
@@ -58,40 +48,24 @@ def started(self) -> bool:
5848

5949
return super().started
6050

61-
@property
62-
def _running_status_notified(self) -> bool:
63-
"""Check that the latest running state change notification was sent.
64-
65-
Returns:
66-
True if the latest running state change notification was sent, False otherwise.
67-
"""
68-
return self.running_state_change_synced == self.update_time
69-
70-
def _set_running_status_notified(self) -> None:
71-
"""Mark the latest running state change notification as sent."""
72-
object.__setattr__(self, "running_state_change_synced", self.update_time)
73-
74-
@property
7551
# noqa is needed because of a bug in pydoclint that makes it think a `return` without a return
7652
# value needs documenting
77-
def missed_runs(self) -> Iterator[datetime]: # noqa: DOC405
53+
def missed_runs(self, since: datetime) -> Iterator[datetime]: # noqa: DOC405
7854
"""Yield all missed runs of a dispatch.
7955
8056
Yields all missed runs of a dispatch.
8157
82-
If a running state change notification was not sent in time
83-
due to connection issues, this method will yield all missed runs
84-
since the last sent notification.
58+
Args:
59+
since: The time to start checking for missed runs.
8560
8661
Returns:
8762
A generator that yields all missed runs of a dispatch.
88-
"""
89-
if self.update_time == self.running_state_change_synced:
90-
return
9163
92-
from_time = self.update_time
64+
Yields:
65+
datetime: The missed run.
66+
"""
9367
now = datetime.now(tz=timezone.utc)
9468

95-
while (next_run := self.next_run_after(from_time)) and next_run < now:
69+
while (next_run := self.next_run_after(since)) and next_run < now:
9670
yield next_run
97-
from_time = next_run
71+
since = next_run

src/frequenz/dispatch/actor.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,3 @@ async def _send_running_state_change(self, dispatch: Dispatch) -> None:
359359
dispatch: The dispatch that changed.
360360
"""
361361
await self._running_state_change_sender.send(dispatch)
362-
# Update the last sent notification time
363-
# so we know if this change was already sent
364-
dispatch._set_running_status_notified() # pylint: disable=protected-access

tests/test_frequenz_dispatch.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ async def _test_new_dispatch_created(
144144
assert False, "Expected a created event"
145145
case Created(dispatch):
146146
received = Dispatch(update_dispatch(sample, dispatch))
147-
received._set_running_status_notified() # pylint: disable=protected-access
148-
dispatch._set_running_status_notified() # pylint: disable=protected-access
149147
assert dispatch == received
150148

151149
return dispatch
@@ -184,10 +182,7 @@ async def test_existing_dispatch_updated(
184182
case Created(dispatch) | Deleted(dispatch):
185183
assert False, f"Expected an updated event, got {dispatch_event}"
186184
case Updated(dispatch):
187-
assert dispatch == Dispatch(
188-
updated,
189-
running_state_change_synced=dispatch.running_state_change_synced,
190-
)
185+
assert dispatch == Dispatch(updated)
191186

192187
await asyncio.sleep(1)
193188

@@ -212,7 +207,6 @@ async def test_existing_dispatch_deleted(
212207
assert False, "Expected a deleted event"
213208
case Deleted(dispatch):
214209
sample._set_deleted() # pylint: disable=protected-access
215-
dispatch._set_running_status_notified() # pylint: disable=protected-access
216210
assert dispatch == sample
217211

218212

@@ -352,9 +346,6 @@ async def test_dispatch_schedule(
352346
# Expect notification of the dispatch being ready to run
353347
ready_dispatch = await actor_env.running_state_change.receive()
354348

355-
# Set flag we expect to be different to compare the dispatch with the one received
356-
dispatch._set_running_status_notified() # pylint: disable=protected-access
357-
358349
assert ready_dispatch == dispatch
359350

360351
assert dispatch.duration is not None

0 commit comments

Comments
 (0)