Skip to content

Commit 0f7631a

Browse files
committed
Update ReceiverFetcher to be compatible with Broadcast channels
The channel package recently renamed the `maxsize` parameter to `limit`. That is now done with the `ReceiverFetcher` and all classes that implement the `ReceiverFetcher`. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent b93f11a commit 0f7631a

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

examples/battery_pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ async def main() -> None:
3030

3131
battery_pool = microgrid.battery_pool()
3232
receivers = [
33-
battery_pool.soc.new_receiver(maxsize=1),
34-
battery_pool.capacity.new_receiver(maxsize=1),
33+
battery_pool.soc.new_receiver(limit=1),
34+
battery_pool.capacity.new_receiver(limit=1),
3535
# pylint: disable=protected-access
36-
battery_pool._system_power_bounds.new_receiver(maxsize=1),
36+
battery_pool._system_power_bounds.new_receiver(limit=1),
3737
# pylint: enable=protected-access
3838
]
3939

src/frequenz/sdk/_internal/_channels.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ class ReceiverFetcher(typing.Generic[T_co], typing.Protocol):
1616
"""An interface that just exposes a `new_receiver` method."""
1717

1818
@abc.abstractmethod
19-
def new_receiver(self, *, maxsize: int = 50) -> Receiver[T_co]:
19+
def new_receiver(self, *, limit: int = 50) -> Receiver[T_co]:
2020
"""Get a receiver from the channel.
2121
2222
Args:
23-
maxsize: The maximum size of the receiver.
23+
limit: The maximum size of the receiver.
2424
2525
Returns:
2626
A receiver instance.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ def update_working_batteries(self, new_working_batteries: set[int]) -> None:
4040
"""
4141

4242
@abstractmethod
43-
def new_receiver(self, maxsize: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
43+
def new_receiver(self, limit: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
4444
"""Return new receiver for the aggregated metric results.
4545
4646
Args:
47-
maxsize: Buffer size of the receiver
47+
limit: Buffer size of the receiver
4848
4949
Returns:
5050
Receiver for the metric results.
@@ -119,18 +119,18 @@ def name(cls) -> str:
119119
"""
120120
return "SendOnUpdate"
121121

122-
def new_receiver(self, maxsize: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
122+
def new_receiver(self, limit: int | None = RECEIVER_MAX_SIZE) -> Receiver[T]:
123123
"""Return new receiver for the aggregated metric results.
124124
125125
Args:
126-
maxsize: Buffer size of the receiver
126+
limit: Buffer size of the receiver
127127
128128
Returns:
129129
Receiver for the metric results.
130130
"""
131-
if maxsize is None:
131+
if limit is None:
132132
return self._result_channel.new_receiver()
133-
return self._result_channel.new_receiver(limit=maxsize)
133+
return self._result_channel.new_receiver(limit=limit)
134134

135135
def update_working_batteries(self, new_working_batteries: set[int]) -> None:
136136
"""Update set of the working batteries.

tests/timeseries/_battery_pool/test_battery_pool.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ async def run_capacity_test( # pylint: disable=too-many-locals
644644
sampling_rate=0.05,
645645
)
646646

647-
capacity_receiver = battery_pool.capacity.new_receiver(maxsize=50)
647+
capacity_receiver = battery_pool.capacity.new_receiver(limit=50)
648648

649649
# First metrics delivers slower because of the startup delay in the pool.
650650
msg = await asyncio.wait_for(
@@ -838,7 +838,7 @@ async def run_soc_test(setup_args: SetupArgs) -> None:
838838
sampling_rate=0.05,
839839
)
840840

841-
receiver = battery_pool.soc.new_receiver(maxsize=50)
841+
receiver = battery_pool.soc.new_receiver(limit=50)
842842

843843
# First metrics delivers slower because of the startup delay in the pool.
844844
msg = await asyncio.wait_for(
@@ -992,7 +992,7 @@ async def run_power_bounds_test( # pylint: disable=too-many-locals
992992
)
993993

994994
# pylint: disable=protected-access
995-
receiver = battery_pool._system_power_bounds.new_receiver(maxsize=50)
995+
receiver = battery_pool._system_power_bounds.new_receiver(limit=50)
996996
# pylint: enable=protected-access
997997

998998
# First metrics delivers slower because of the startup delay in the pool.

0 commit comments

Comments
 (0)