Skip to content

Commit 370db17

Browse files
committed
Add a creation_time attribute to Proposals
This is used to identify proposals that are too old, so that they can be removed from consideration when the PowerManager calculates target power. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent f8f3069 commit 370db17

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/frequenz/sdk/actor/_power_managing/_base_classes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ class Proposal:
207207
priority: int
208208
"""The priority of the actor sending the proposal."""
209209

210+
creation_time: float
211+
"""The loop time when the proposal is created.
212+
213+
This is used by the power manager to determine the age of the proposal.
214+
"""
215+
210216
request_timeout: datetime.timedelta = datetime.timedelta(seconds=5.0)
211217
"""The maximum amount of time to wait for the request to be fulfilled."""
212218

src/frequenz/sdk/timeseries/battery_pool/_battery_pool.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ async def propose_power(
132132
bounds=bounds,
133133
component_ids=self._battery_pool._batteries,
134134
priority=self._priority,
135+
creation_time=asyncio.get_running_loop().time(),
135136
request_timeout=request_timeout,
136137
)
137138
)
@@ -177,6 +178,7 @@ async def propose_charge(
177178
bounds=timeseries.Bounds(None, None),
178179
component_ids=self._battery_pool._batteries,
179180
priority=self._priority,
181+
creation_time=asyncio.get_running_loop().time(),
180182
request_timeout=request_timeout,
181183
)
182184
)
@@ -222,6 +224,7 @@ async def propose_discharge(
222224
bounds=timeseries.Bounds(None, None),
223225
component_ids=self._battery_pool._batteries,
224226
priority=self._priority,
227+
creation_time=asyncio.get_running_loop().time(),
225228
request_timeout=request_timeout,
226229
)
227230
)

tests/actor/_power_managing/test_matryoshka.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Tests for the Matryoshka power manager algorithm."""
55

6+
import asyncio
67
from datetime import datetime, timezone
78

89
from frequenz.sdk import timeseries
@@ -46,6 +47,7 @@ def tgt_power( # pylint: disable=too-many-arguments
4647
None if bounds[1] is None else Power.from_watts(bounds[1]),
4748
),
4849
priority=priority,
50+
creation_time=asyncio.get_event_loop().time(),
4951
),
5052
self._system_bounds,
5153
must_send,

0 commit comments

Comments
 (0)