|
9 | 9 | from dataclasses import dataclass |
10 | 10 | from datetime import timedelta |
11 | 11 | from typing import Any, Awaitable |
| 12 | +from warnings import warn |
12 | 13 |
|
13 | 14 | from frequenz.channels import Broadcast, Receiver, Sender, select |
14 | 15 | from frequenz.channels.timer import SkipMissedAndDrift, Timer |
@@ -60,6 +61,46 @@ def components(self) -> TargetComponents: |
60 | 61 | _src: Dispatch |
61 | 62 | """The dispatch that triggered this update.""" |
62 | 63 |
|
| 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 | + # Use components if target is not provided (backwards compatibility) |
| 89 | + if target is None: |
| 90 | + if components is None: |
| 91 | + raise ValueError("One of 'target' or 'components' must be set.") |
| 92 | + target = components |
| 93 | + warn( |
| 94 | + "'components' is deprecated, use 'target' instead.", |
| 95 | + DeprecationWarning, |
| 96 | + stacklevel=2, |
| 97 | + ) |
| 98 | + |
| 99 | + object.__setattr__(self, "target", target) |
| 100 | + object.__setattr__(self, "dry_run", dry_run) |
| 101 | + object.__setattr__(self, "options", options) |
| 102 | + object.__setattr__(self, "_src", _src) |
| 103 | + |
63 | 104 |
|
64 | 105 | class ActorDispatcher(BackgroundService): |
65 | 106 | """Helper class to manage actors based on dispatches. |
|
0 commit comments