Skip to content

Commit 581ce72

Browse files
committed
Make DispatchUpdate c'tor accept components
To stay backwards compatible. Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent cb74e80 commit 581ce72

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/frequenz/dispatch/_actor_dispatcher.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from dataclasses import dataclass
1010
from datetime import timedelta
1111
from typing import Any, Awaitable
12+
from warnings import warn
1213

1314
from frequenz.channels import Broadcast, Receiver, Sender, select
1415
from frequenz.channels.timer import SkipMissedAndDrift, Timer
@@ -60,6 +61,43 @@ def components(self) -> TargetComponents:
6061
_src: Dispatch
6162
"""The dispatch that triggered this update."""
6263

64+
def __init__(
65+
self,
66+
*,
67+
target: TargetComponents | None = None,
68+
components: TargetComponents | None = None,
69+
dry_run: bool,
70+
options: dict[str, Any],
71+
_src: Dispatch,
72+
) -> None:
73+
"""Initialize the DispatchInfo.
74+
75+
Args:
76+
target: Target components to be used.
77+
components: Deprecated alias for `target`.
78+
dry_run: Whether this is a dry run.
79+
options: Additional options.
80+
_src: The dispatch that triggered this update.
81+
82+
Raises:
83+
ValueError: If both `target` and `components` are set, or if neither is set.
84+
"""
85+
if target is not None and components is not None:
86+
raise ValueError("Only one of 'target' or 'components' can be set.")
87+
88+
if target is None:
89+
if components is None:
90+
raise ValueError("One of 'target' or 'components' must be set.")
91+
target = components
92+
warn(
93+
"'components' is deprecated, use 'target' instead.", DeprecationWarning
94+
)
95+
96+
object.__setattr__(self, "target", target)
97+
object.__setattr__(self, "dry_run", dry_run)
98+
object.__setattr__(self, "options", options)
99+
object.__setattr__(self, "_src", _src)
100+
63101

64102
class ActorDispatcher(BackgroundService):
65103
"""Helper class to manage actors based on dispatches.

0 commit comments

Comments
 (0)