Skip to content

Commit 17d4a76

Browse files
committed
Add optional name to actors
This improves actors debuggeability. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent c5ddca9 commit 17d4a76

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/frequenz/sdk/actor/_config_managing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,19 @@ def __init__(
3535
config_path: pathlib.Path | str,
3636
output: Sender[Config],
3737
event_types: abc.Set[FileWatcher.EventType] = frozenset(FileWatcher.EventType),
38+
*,
39+
name: str | None = None,
3840
) -> None:
3941
"""Initialize this instance.
4042
4143
Args:
4244
config_path: The path to the TOML file with the configuration.
4345
output: The sender to send the config to.
4446
event_types: The set of event types to monitor.
47+
name: The name of the actor. If `None`, `str(id(self))` will
48+
be used. This is used mostly for debugging purposes.
4549
"""
46-
super().__init__()
50+
super().__init__(name=name)
4751
self._config_path: pathlib.Path = (
4852
config_path
4953
if isinstance(config_path, pathlib.Path)

src/frequenz/sdk/actor/_data_sourcing/data_sourcing.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ def __init__(
1717
self,
1818
request_receiver: Receiver[ComponentMetricRequest],
1919
registry: ChannelRegistry,
20+
*,
21+
name: str | None = None,
2022
) -> None:
2123
"""Create a `DataSourcingActor` instance.
2224
2325
Args:
2426
request_receiver: A channel receiver to accept metric requests from.
2527
registry: A channel registry. To be replaced by a singleton
2628
instance.
29+
name: The name of the actor. If `None`, `str(id(self))` will be used. This
30+
is used mostly for debugging purposes.
2731
"""
28-
super().__init__()
32+
super().__init__(name=name)
2933
self._request_receiver = request_receiver
3034
self._microgrid_api_source = MicrogridApiSource(registry)
3135

src/frequenz/sdk/actor/_resampling.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__( # pylint: disable=too-many-arguments
3232
data_sourcing_request_sender: Sender[ComponentMetricRequest],
3333
resampling_request_receiver: Receiver[ComponentMetricRequest],
3434
config: ResamplerConfig,
35+
name: str | None = None,
3536
) -> None:
3637
"""Initialize an instance.
3738
@@ -44,8 +45,10 @@ def __init__( # pylint: disable=too-many-arguments
4445
resampling_request_receiver: The receiver to use to receive new
4546
resampmling subscription requests.
4647
config: The configuration for the resampler.
48+
name: The name of the actor. If `None`, `str(id(self))` will be used. This
49+
is used mostly for debugging purposes.
4750
"""
48-
super().__init__()
51+
super().__init__(name=name)
4952
self._channel_registry: ChannelRegistry = channel_registry
5053
self._data_sourcing_request_sender: Sender[
5154
ComponentMetricRequest

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ def __init__(
183183
channel_registry: ChannelRegistry,
184184
battery_status_sender: Sender[BatteryStatus],
185185
wait_for_data_sec: float = 2,
186+
*,
187+
name: str | None = None,
186188
) -> None:
187189
"""Create class instance.
188190
@@ -194,8 +196,10 @@ def __init__(
194196
working.
195197
wait_for_data_sec: How long actor should wait before processing first
196198
request. It is a time needed to collect first components data.
199+
name: The name of the actor. If `None`, `str(id(self))` will be used. This
200+
is used mostly for debugging purposes.
197201
"""
198-
super().__init__()
202+
super().__init__(name=name)
199203
self._requests_receiver = requests_receiver
200204
self._channel_registry = channel_registry
201205
self._wait_for_data_sec = wait_for_data_sec

0 commit comments

Comments
 (0)