Skip to content

Commit 8b93da9

Browse files
authored
Fixes to the PowerDistributingActor (#1020)
2 parents 5ad1a9c + 81d0bca commit 8b93da9

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
- Fixed a bug in `ConfigManagingActor` that was not properly comparing the event path to the config file path when the config file is a relative path.
4141
- Re-expose `ComponentMetricId` to the docs.
4242
- Fixed typing ambiguities when building composite formulas on streaming data.
43+
- Fixed a bug that was causing the `PowerDistributor` to exit if power requests to PV inverters or EV chargers timeout.

src/frequenz/sdk/actor/power_distributing/_component_managers/_ev_charger_manager/_ev_charger_manager.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,29 +334,29 @@ async def _set_api_power(
334334
succeeded_components: set[int] = set()
335335
failed_power = Power.zero()
336336
for component_id, task in tasks.items():
337-
exc = task.exception()
338-
if exc is not None:
339-
failed_components.add(component_id)
340-
failed_power += target_power_changes[component_id]
337+
try:
338+
task.result()
339+
except asyncio.CancelledError:
340+
_logger.warning(
341+
"Timeout while setting power to EV charger %s", component_id
342+
)
343+
except ClientError as exc:
344+
_logger.warning(
345+
"Got a client error while setting power to EV charger %s: %s",
346+
component_id,
347+
exc,
348+
)
349+
except Exception: # pylint: disable=broad-except
350+
_logger.exception(
351+
"Unknown error while setting power to EV charger: %s", component_id
352+
)
341353
else:
342354
succeeded_components.add(component_id)
355+
continue
356+
357+
failed_components.add(component_id)
358+
failed_power += target_power_changes[component_id]
343359

344-
match task.exception():
345-
case asyncio.CancelledError():
346-
_logger.warning(
347-
"Timeout while setting power to EV charger %s", component_id
348-
)
349-
case ClientError() as err:
350-
_logger.warning(
351-
"Got a client error while setting power to EV charger %s: %s",
352-
component_id,
353-
err,
354-
)
355-
case Exception():
356-
_logger.exception(
357-
"Unknown error while setting power to EV charger: %s",
358-
component_id,
359-
)
360360
if failed_components:
361361
return PartialFailure(
362362
failed_components=failed_components,

src/frequenz/sdk/actor/power_distributing/_component_managers/_pv_inverter_manager/_pv_inverter_manager.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -193,29 +193,30 @@ async def _set_api_power( # pylint: disable=too-many-locals
193193
succeeded_components: set[int] = set()
194194
failed_power = Power.zero()
195195
for component_id, task in tasks.items():
196-
exc = task.exception()
197-
if exc is not None:
198-
failed_components.add(component_id)
199-
failed_power += allocations[component_id]
196+
try:
197+
task.result()
198+
except asyncio.CancelledError:
199+
_logger.warning(
200+
"Timeout while setting power to PV inverter %s", component_id
201+
)
202+
except ClientError as exc:
203+
_logger.warning(
204+
"Got a client error while setting power to PV inverter %s: %s",
205+
component_id,
206+
exc,
207+
)
208+
except Exception: # pylint: disable=broad-except
209+
_logger.exception(
210+
"Unknown error while setting power to PV inverter: %s",
211+
component_id,
212+
)
200213
else:
201214
succeeded_components.add(component_id)
215+
continue
216+
217+
failed_components.add(component_id)
218+
failed_power += allocations[component_id]
202219

203-
match task.exception():
204-
case asyncio.CancelledError():
205-
_logger.warning(
206-
"Timeout while setting power to PV inverter %s", component_id
207-
)
208-
case ClientError() as err:
209-
_logger.warning(
210-
"Got a client error while setting power to PV inverter %s: %s",
211-
component_id,
212-
err,
213-
)
214-
case Exception():
215-
_logger.exception(
216-
"Unknown error while setting power to PV inverter: %s",
217-
component_id,
218-
)
219220
if failed_components:
220221
await self._results_sender.send(
221222
PartialFailure(

0 commit comments

Comments
 (0)