Reduce complexity in PowerDistributingActor #1032
Labels
part:power-distribution
priority:low
This should be addressed only if there is nothing else on the table
type:tech-debt
Improves the project without visible changes for users
What's needed?
Currently the
PowerDistributingActor
uses asyncio primitives to manage tasks and power requests. This approach makes the code complex and prone to errors because it mixes the actor's logic with task synchronization and error handling.Proposed solution
Once
PersistentTaskGroup
is available in https://github.com/frequenz-floss/frequenz-core-python it can be used in thePowerDistributingActor
, that should make the code less convoluted, less error-prone and focus just in the logic of the actor without the need of taking care of tasks logic.This is the comment with the proposal:
I actually stayed on this issue thinking about it again...
[.... one hour later due to some of the changes you did with the request ID :D ...]
It was a good exercise to see how to apply the new class. The result is pretty different to what I had in mind before, and it doesn't look particularly simple either in retrospect, but I think it is more efficient, because we only keep one task for the same
req_id
, as long as we have quests queued up, instead of starting and finishing a task for every pending request.At some point I want to add a way to get
as_completed()
as aReceiver
, so we can put it in aselect()
, like:But for now we can live with using it with
timeout=0
so it doesn't block, and we only ACK finished tasks after we handle a power request, which should be OK, we should receive requests often enough I guess.Additional context
See the original post and draft example (not tested) in #1023 (comment)
The text was updated successfully, but these errors were encountered: