Skip to content

Commit f8f3069

Browse files
committed
Retry only once on PartialFailure
When the PowerManager receives a `PartialFailure`, in many cases, resending the request would fix it, because the power distributor would have new information on how to redistribute differently. But this doesn't always work, for example in single battery locations or if all batteries are in an UNCERTAIN state, in which case the power distributor has to retry with the same batteries. For this reason, if we don't have a limit on such retries from the PowerManager, we'd get into an infinite loop that doesn't have any delay inbetween retries. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent a29e600 commit f8f3069

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ async def _send_updated_target_power(
180180
@override
181181
async def _run(self) -> None:
182182
"""Run the power managing actor."""
183+
last_result_partial_failure = False
183184
async for selected in select(
184185
self._proposals_receiver,
185186
self._bounds_subscription_receiver,
@@ -234,9 +235,17 @@ async def _run(self) -> None:
234235
self._distribution_results[
235236
frozenset(result.request.component_ids)
236237
] = result
238+
if not isinstance(result, power_distributing.Success):
239+
_logger.warning(
240+
"PowerManagingActor: PowerDistributing failed: %s", result
241+
)
237242
match result:
238243
case power_distributing.PartialFailure(request):
239-
await self._send_updated_target_power(
240-
frozenset(request.component_ids), None, must_send=True
241-
)
244+
if not last_result_partial_failure:
245+
last_result_partial_failure = True
246+
await self._send_updated_target_power(
247+
frozenset(request.component_ids), None, must_send=True
248+
)
249+
case power_distributing.Success():
250+
last_result_partial_failure = False
242251
await self._send_reports(frozenset(result.request.component_ids))

0 commit comments

Comments
 (0)