Skip to content

Commit 66f602f

Browse files
committed
fixup! Support handling proposals from incremental actors in the PowerManager
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 9a2b67b commit 66f602f

File tree

1 file changed

+22
-67
lines changed

1 file changed

+22
-67
lines changed

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

Lines changed: 22 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,6 @@ def __init__( # pylint: disable=too-many-arguments
9393
] = {}
9494
self._distribution_results: dict[frozenset[int], power_distributing.Result] = {}
9595

96-
self._highest_known_priority: dict[frozenset[int], int] = {}
97-
self._highest_priority_is_shifting: dict[frozenset[int], bool] = {}
98-
9996
self._non_shifting_group: BaseAlgorithm = Matryoshka(
10097
max_proposal_age=timedelta(seconds=60.0)
10198
)
@@ -116,54 +113,29 @@ async def _send_reports(self, component_ids: frozenset[int]) -> None:
116113
if bounds is None:
117114
_logger.warning("PowerManagingActor: No bounds for %s", component_ids)
118115
return
119-
if not self._highest_priority_is_shifting.get(component_ids, False):
120-
for priority, sender in self._non_shifting_subscriptions.get(
121-
component_ids, {}
122-
).items():
123-
status = self._non_shifting_group.get_status(
124-
component_ids,
125-
priority,
126-
bounds,
127-
self._distribution_results.get(component_ids),
128-
)
129-
await sender.send(status)
130-
for priority, sender in self._shifting_subscriptions.get(
131-
component_ids, {}
132-
).items():
133-
status = self._shifting_group.get_status(
134-
component_ids,
135-
priority,
136-
self._calculate_remaining_bounds(
137-
bounds,
138-
self._non_shifting_group.get_target_power(component_ids),
139-
),
140-
self._distribution_results.get(component_ids),
141-
)
142-
await sender.send(status)
143-
else:
144-
for priority, sender in self._shifting_subscriptions.get(
145-
component_ids, {}
146-
).items():
147-
status = self._shifting_group.get_status(
148-
component_ids,
149-
priority,
116+
for priority, sender in self._shifting_subscriptions.get(
117+
component_ids, {}
118+
).items():
119+
status = self._shifting_group.get_status(
120+
component_ids,
121+
priority,
122+
bounds,
123+
self._distribution_results.get(component_ids),
124+
)
125+
await sender.send(status)
126+
for priority, sender in self._non_shifting_subscriptions.get(
127+
component_ids, {}
128+
).items():
129+
status = self._non_shifting_group.get_status(
130+
component_ids,
131+
priority,
132+
self._calculate_remaining_bounds(
150133
bounds,
151-
self._distribution_results.get(component_ids),
152-
)
153-
await sender.send(status)
154-
for priority, sender in self._non_shifting_subscriptions.get(
155-
component_ids, {}
156-
).items():
157-
status = self._non_shifting_group.get_status(
158-
component_ids,
159-
priority,
160-
self._calculate_remaining_bounds(
161-
bounds,
162-
self._shifting_group.get_target_power(component_ids),
163-
),
164-
self._distribution_results.get(component_ids),
165-
)
166-
await sender.send(status)
134+
self._shifting_group.get_target_power(component_ids),
135+
),
136+
self._distribution_results.get(component_ids),
137+
)
138+
await sender.send(status)
167139

168140
async def _bounds_tracker(
169141
self,
@@ -388,16 +360,6 @@ async def _run(self) -> None:
388360
if proposal.component_ids not in self._bound_tracker_tasks:
389361
self._add_system_bounds_tracker(proposal.component_ids)
390362

391-
if proposal.priority > self._highest_known_priority.setdefault(
392-
proposal.component_ids, -sys.maxsize - 1
393-
):
394-
self._highest_known_priority[proposal.component_ids] = (
395-
proposal.priority
396-
)
397-
self._highest_priority_is_shifting[proposal.component_ids] = (
398-
proposal.in_shifting_group
399-
)
400-
401363
# TODO: must_send=True forces a new request to # pylint: disable=fixme
402364
# be sent to the PowerDistributor, even if there's no change in power.
403365
#
@@ -439,13 +401,6 @@ async def _run(self) -> None:
439401

440402
if component_ids not in self._bound_tracker_tasks:
441403
self._add_system_bounds_tracker(component_ids)
442-
if priority > self._highest_known_priority.setdefault(
443-
component_ids, -sys.maxsize - 1
444-
):
445-
self._highest_known_priority[component_ids] = priority
446-
self._highest_priority_is_shifting[component_ids] = (
447-
in_shifting_group
448-
)
449404

450405
elif selected_from(selected, self._power_distributing_results_receiver):
451406
from .. import ( # pylint: disable=import-outside-toplevel

0 commit comments

Comments
 (0)