frequenz-dispatch 1.0.3__tar.gz → 1.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {frequenz_dispatch-1.0.3/src/frequenz_dispatch.egg-info → frequenz_dispatch-1.0.4}/PKG-INFO +29 -26
- frequenz_dispatch-1.0.4/RELEASE_NOTES.md +10 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/pyproject.toml +38 -29
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/__init__.py +7 -7
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_actor_dispatcher.py +113 -109
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_bg_service.py +51 -18
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_dispatch.py +7 -18
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_dispatcher.py +41 -36
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_event.py +1 -1
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_merge_strategies.py +29 -8
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info}/PKG-INFO +29 -26
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/SOURCES.txt +2 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/requires.txt +27 -23
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/scm_file_list.json +52 -0
- frequenz_dispatch-1.0.4/src/frequenz_dispatch.egg-info/scm_version.json +8 -0
- frequenz_dispatch-1.0.3/RELEASE_NOTES.md +0 -22
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/LICENSE +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/MANIFEST.in +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/README.md +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/setup.cfg +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/conftest.py +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/py.typed +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/dependency_links.txt +0 -0
- {frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz_dispatch.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: frequenz-dispatch
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: A highlevel interface for the dispatch API
|
|
5
5
|
Author-email: Frequenz Energy-as-a-Service GmbH <floss@frequenz.com>
|
|
6
|
-
License: MIT
|
|
6
|
+
License-Expression: MIT
|
|
7
7
|
Project-URL: Documentation, https://frequenz-floss.github.io/frequenz-dispatch-python/
|
|
8
8
|
Project-URL: Changelog, https://github.com/frequenz-floss/frequenz-dispatch-python/releases
|
|
9
9
|
Project-URL: Issues, https://github.com/frequenz-floss/frequenz-dispatch-python/issues
|
|
@@ -12,7 +12,6 @@ Project-URL: Support, https://github.com/frequenz-floss/frequenz-dispatch-python
|
|
|
12
12
|
Keywords: frequenz,python,actor,frequenz-dispatch,dispatch,highlevel,api
|
|
13
13
|
Classifier: Development Status :: 3 - Alpha
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
16
15
|
Classifier: Programming Language :: Python :: 3
|
|
17
16
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
17
|
Classifier: Topic :: Software Development :: Libraries
|
|
@@ -25,45 +24,49 @@ Requires-Dist: frequenz-sdk<1.0.0-rc2300,>=1.0.0-rc2100
|
|
|
25
24
|
Requires-Dist: frequenz-channels<2.0.0,>=1.6.1
|
|
26
25
|
Requires-Dist: frequenz-client-dispatch<2.0.0,>=0.11.3
|
|
27
26
|
Requires-Dist: frequenz-client-base<0.12.0,>=0.11.0
|
|
27
|
+
Requires-Dist: frequenz-client-common<0.4.0,>=0.3.8
|
|
28
|
+
Requires-Dist: frequenz-core<2.0.0,>=1.0.2
|
|
29
|
+
Requires-Dist: grpcio<2.0.0,>=1.80.0
|
|
28
30
|
Provides-Extra: dev-flake8
|
|
29
31
|
Requires-Dist: flake8==7.3.0; extra == "dev-flake8"
|
|
32
|
+
Requires-Dist: flake8-datetimez==26.8.1; extra == "dev-flake8"
|
|
30
33
|
Requires-Dist: flake8-docstrings==1.7.0; extra == "dev-flake8"
|
|
31
34
|
Requires-Dist: flake8-pyproject==1.2.4; extra == "dev-flake8"
|
|
32
|
-
Requires-Dist: pydoclint==0.
|
|
35
|
+
Requires-Dist: pydoclint==0.9.1; extra == "dev-flake8"
|
|
33
36
|
Requires-Dist: pydocstyle==6.3.0; extra == "dev-flake8"
|
|
34
37
|
Provides-Extra: dev-formatting
|
|
35
|
-
Requires-Dist: black==
|
|
36
|
-
Requires-Dist: isort==
|
|
38
|
+
Requires-Dist: black==26.5.1; extra == "dev-formatting"
|
|
39
|
+
Requires-Dist: isort==9.0.1; extra == "dev-formatting"
|
|
37
40
|
Provides-Extra: dev-mkdocs
|
|
38
|
-
Requires-Dist: black==
|
|
39
|
-
Requires-Dist: Markdown==3.10.
|
|
40
|
-
Requires-Dist: mike==2.
|
|
41
|
-
Requires-Dist: mkdocs-gen-files==0.6.
|
|
42
|
-
Requires-Dist: mkdocs-literate-nav==0.6.
|
|
41
|
+
Requires-Dist: black==26.5.1; extra == "dev-mkdocs"
|
|
42
|
+
Requires-Dist: Markdown==3.10.3; extra == "dev-mkdocs"
|
|
43
|
+
Requires-Dist: mike==2.2.0; extra == "dev-mkdocs"
|
|
44
|
+
Requires-Dist: mkdocs-gen-files==0.6.1; extra == "dev-mkdocs"
|
|
45
|
+
Requires-Dist: mkdocs-literate-nav==0.6.3; extra == "dev-mkdocs"
|
|
43
46
|
Requires-Dist: mkdocs-macros-plugin==1.5.0; extra == "dev-mkdocs"
|
|
44
|
-
Requires-Dist: mkdocs-material==9.7.
|
|
45
|
-
Requires-Dist: mkdocstrings[python]==1.0.
|
|
46
|
-
Requires-Dist: mkdocstrings-python==
|
|
47
|
-
Requires-Dist: frequenz-repo-config[lib]==0.
|
|
47
|
+
Requires-Dist: mkdocs-material==9.7.7; extra == "dev-mkdocs"
|
|
48
|
+
Requires-Dist: mkdocstrings[python]==1.0.6; extra == "dev-mkdocs"
|
|
49
|
+
Requires-Dist: mkdocstrings-python==2.0.8; extra == "dev-mkdocs"
|
|
50
|
+
Requires-Dist: frequenz-repo-config[lib]==0.19.0; extra == "dev-mkdocs"
|
|
48
51
|
Provides-Extra: dev-mypy
|
|
49
|
-
Requires-Dist: mypy==
|
|
52
|
+
Requires-Dist: mypy==2.3.1; extra == "dev-mypy"
|
|
50
53
|
Requires-Dist: grpc-stubs==1.53.0.6; extra == "dev-mypy"
|
|
51
|
-
Requires-Dist: types-Markdown==3.10.2.
|
|
54
|
+
Requires-Dist: types-Markdown==3.10.2.20260712; extra == "dev-mypy"
|
|
52
55
|
Requires-Dist: frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-mypy"
|
|
53
56
|
Provides-Extra: dev-noxfile
|
|
54
|
-
Requires-Dist: uv==0.
|
|
55
|
-
Requires-Dist: nox==
|
|
56
|
-
Requires-Dist: frequenz-repo-config[lib]==0.
|
|
57
|
+
Requires-Dist: uv==0.12.13; extra == "dev-noxfile"
|
|
58
|
+
Requires-Dist: nox==2026.8.17; extra == "dev-noxfile"
|
|
59
|
+
Requires-Dist: frequenz-repo-config[lib]==0.19.0; extra == "dev-noxfile"
|
|
57
60
|
Provides-Extra: dev-pylint
|
|
58
|
-
Requires-Dist: pylint==4.0.
|
|
61
|
+
Requires-Dist: pylint==4.0.8; extra == "dev-pylint"
|
|
59
62
|
Requires-Dist: frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]; extra == "dev-pylint"
|
|
60
63
|
Provides-Extra: dev-pytest
|
|
61
|
-
Requires-Dist: pytest==9.
|
|
62
|
-
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.
|
|
64
|
+
Requires-Dist: pytest==9.1.1; extra == "dev-pytest"
|
|
65
|
+
Requires-Dist: frequenz-repo-config[extra-lint-examples]==0.19.0; extra == "dev-pytest"
|
|
63
66
|
Requires-Dist: pytest-mock==3.15.1; extra == "dev-pytest"
|
|
64
|
-
Requires-Dist: pytest-asyncio==1.
|
|
65
|
-
Requires-Dist: async-solipsism==0.
|
|
66
|
-
Requires-Dist: time-machine==3.
|
|
67
|
+
Requires-Dist: pytest-asyncio==1.4.0; extra == "dev-pytest"
|
|
68
|
+
Requires-Dist: async-solipsism==0.9; extra == "dev-pytest"
|
|
69
|
+
Requires-Dist: time-machine==3.5.1; extra == "dev-pytest"
|
|
67
70
|
Provides-Extra: dev
|
|
68
71
|
Requires-Dist: frequenz-dispatch[dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]; extra == "dev"
|
|
69
72
|
Dynamic: license-file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Dispatch Highlevel Interface Release Notes
|
|
2
|
+
|
|
3
|
+
## Enhancements
|
|
4
|
+
|
|
5
|
+
- Improved docstring documentation across the project.
|
|
6
|
+
|
|
7
|
+
## Bug Fixes
|
|
8
|
+
|
|
9
|
+
* Fixed documentation cross-references to dependencies by updating the mkdocstrings inventories to match the minimum dependency versions and adding the missing `frequenz-client-base` inventory.
|
|
10
|
+
* Declared the missing direct dependencies `frequenz-client-common`, `frequenz-core` and `grpcio`, which were previously only pulled in indirectly through `frequenz-client-dispatch`.
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
[build-system]
|
|
5
5
|
requires = [
|
|
6
|
-
"setuptools ==
|
|
7
|
-
"setuptools_scm[toml] ==
|
|
8
|
-
"frequenz-repo-config[lib] == 0.
|
|
6
|
+
"setuptools == 84.0.0",
|
|
7
|
+
"setuptools_scm[toml] == 10.2.1",
|
|
8
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
9
9
|
]
|
|
10
10
|
build-backend = "setuptools.build_meta"
|
|
11
11
|
|
|
@@ -13,7 +13,8 @@ build-backend = "setuptools.build_meta"
|
|
|
13
13
|
name = "frequenz-dispatch"
|
|
14
14
|
description = "A highlevel interface for the dispatch API"
|
|
15
15
|
readme = "README.md"
|
|
16
|
-
license =
|
|
16
|
+
license = "MIT"
|
|
17
|
+
license-files = ["LICENSE"]
|
|
17
18
|
keywords = [
|
|
18
19
|
"frequenz",
|
|
19
20
|
"python",
|
|
@@ -26,7 +27,6 @@ keywords = [
|
|
|
26
27
|
classifiers = [
|
|
27
28
|
"Development Status :: 3 - Alpha",
|
|
28
29
|
"Intended Audience :: Developers",
|
|
29
|
-
"License :: OSI Approved :: MIT License",
|
|
30
30
|
"Programming Language :: Python :: 3",
|
|
31
31
|
"Programming Language :: Python :: 3 :: Only",
|
|
32
32
|
"Topic :: Software Development :: Libraries",
|
|
@@ -37,11 +37,14 @@ dependencies = [
|
|
|
37
37
|
"typing-extensions >= 4.13.0, < 5.0.0",
|
|
38
38
|
# Make sure to update the version for cross-referencing also in the
|
|
39
39
|
# mkdocs.yml file when changing the version here (look for the config key
|
|
40
|
-
# plugins.mkdocstrings.handlers.python.
|
|
40
|
+
# plugins.mkdocstrings.handlers.python.inventories)
|
|
41
41
|
"frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2300",
|
|
42
42
|
"frequenz-channels >= 1.6.1, < 2.0.0",
|
|
43
43
|
"frequenz-client-dispatch >= 0.11.3, < 2.0.0",
|
|
44
44
|
"frequenz-client-base >= 0.11.0, < 0.12.0",
|
|
45
|
+
"frequenz-client-common >= 0.3.8, < 0.4.0",
|
|
46
|
+
"frequenz-core >= 1.0.2, < 2.0.0",
|
|
47
|
+
"grpcio >= 1.80.0, < 2.0.0",
|
|
45
48
|
]
|
|
46
49
|
dynamic = ["version"]
|
|
47
50
|
|
|
@@ -52,49 +55,50 @@ email = "floss@frequenz.com"
|
|
|
52
55
|
[project.optional-dependencies]
|
|
53
56
|
dev-flake8 = [
|
|
54
57
|
"flake8 == 7.3.0",
|
|
58
|
+
"flake8-datetimez == 26.8.1",
|
|
55
59
|
"flake8-docstrings == 1.7.0",
|
|
56
60
|
"flake8-pyproject == 1.2.4", # For reading the flake8 config from pyproject.toml
|
|
57
|
-
"pydoclint == 0.
|
|
61
|
+
"pydoclint == 0.9.1",
|
|
58
62
|
"pydocstyle == 6.3.0",
|
|
59
63
|
]
|
|
60
|
-
dev-formatting = ["black ==
|
|
64
|
+
dev-formatting = ["black == 26.5.1", "isort == 9.0.1"]
|
|
61
65
|
dev-mkdocs = [
|
|
62
|
-
"black ==
|
|
63
|
-
"Markdown==3.10.
|
|
64
|
-
"mike == 2.
|
|
65
|
-
"mkdocs-gen-files == 0.6.
|
|
66
|
-
"mkdocs-literate-nav == 0.6.
|
|
66
|
+
"black == 26.5.1",
|
|
67
|
+
"Markdown==3.10.3",
|
|
68
|
+
"mike == 2.2.0",
|
|
69
|
+
"mkdocs-gen-files == 0.6.1",
|
|
70
|
+
"mkdocs-literate-nav == 0.6.3",
|
|
67
71
|
"mkdocs-macros-plugin == 1.5.0",
|
|
68
|
-
"mkdocs-material == 9.7.
|
|
69
|
-
"mkdocstrings[python] == 1.0.
|
|
70
|
-
"mkdocstrings-python ==
|
|
71
|
-
"frequenz-repo-config[lib] == 0.
|
|
72
|
+
"mkdocs-material == 9.7.7",
|
|
73
|
+
"mkdocstrings[python] == 1.0.6",
|
|
74
|
+
"mkdocstrings-python == 2.0.8",
|
|
75
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
72
76
|
]
|
|
73
77
|
dev-mypy = [
|
|
74
|
-
"mypy ==
|
|
78
|
+
"mypy == 2.3.1",
|
|
75
79
|
# This dependency introduces breaking changes in patch releases
|
|
76
80
|
"grpc-stubs == 1.53.0.6",
|
|
77
|
-
"types-Markdown == 3.10.2.
|
|
81
|
+
"types-Markdown == 3.10.2.20260712",
|
|
78
82
|
# For checking the noxfile, docs/ script, and tests
|
|
79
83
|
"frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
80
84
|
]
|
|
81
85
|
dev-noxfile = [
|
|
82
|
-
"uv == 0.
|
|
83
|
-
"nox ==
|
|
84
|
-
"frequenz-repo-config[lib] == 0.
|
|
86
|
+
"uv == 0.12.13",
|
|
87
|
+
"nox == 2026.8.17",
|
|
88
|
+
"frequenz-repo-config[lib] == 0.19.0",
|
|
85
89
|
]
|
|
86
90
|
dev-pylint = [
|
|
87
|
-
"pylint == 4.0.
|
|
91
|
+
"pylint == 4.0.8",
|
|
88
92
|
# For checking the noxfile, docs/ script, and tests
|
|
89
93
|
"frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]",
|
|
90
94
|
]
|
|
91
95
|
dev-pytest = [
|
|
92
|
-
"pytest == 9.
|
|
93
|
-
"frequenz-repo-config[extra-lint-examples] == 0.
|
|
96
|
+
"pytest == 9.1.1",
|
|
97
|
+
"frequenz-repo-config[extra-lint-examples] == 0.19.0",
|
|
94
98
|
"pytest-mock == 3.15.1",
|
|
95
|
-
"pytest-asyncio == 1.
|
|
96
|
-
"async-solipsism == 0.
|
|
97
|
-
"time-machine == 3.
|
|
99
|
+
"pytest-asyncio == 1.4.0",
|
|
100
|
+
"async-solipsism == 0.9",
|
|
101
|
+
"time-machine == 3.5.1",
|
|
98
102
|
]
|
|
99
103
|
dev = [
|
|
100
104
|
"frequenz-dispatch[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]",
|
|
@@ -133,6 +137,9 @@ check-yield-types = false
|
|
|
133
137
|
arg-type-hints-in-docstring = false
|
|
134
138
|
arg-type-hints-in-signature = true
|
|
135
139
|
allow-init-docstring = true
|
|
140
|
+
check-class-attributes = true
|
|
141
|
+
check-style-mismatch = true
|
|
142
|
+
require-inline-class-var-docs = true
|
|
136
143
|
|
|
137
144
|
[tool.pylint.similarities]
|
|
138
145
|
ignore-comments = ['yes']
|
|
@@ -169,13 +176,15 @@ disable = [
|
|
|
169
176
|
# coming for external dependencies that are hard to address here, once this is
|
|
170
177
|
# fixed, we can add the following options:
|
|
171
178
|
# -Werror -Wdefault::DeprecationWarning -Wdefault::PendingDeprecationWarning
|
|
172
|
-
addopts = "-W=all
|
|
179
|
+
addopts = "-W=all"
|
|
173
180
|
testpaths = ["tests", "src"]
|
|
181
|
+
asyncio_debug = true
|
|
174
182
|
asyncio_mode = "auto"
|
|
175
183
|
asyncio_default_fixture_loop_scope = "function"
|
|
176
184
|
required_plugins = ["pytest-asyncio", "pytest-mock"]
|
|
177
185
|
|
|
178
186
|
[tool.mypy]
|
|
187
|
+
enable_error_code = ["exhaustive-match"]
|
|
179
188
|
explicit_package_bases = true
|
|
180
189
|
namespace_packages = true
|
|
181
190
|
# This option disables mypy cache, and it is sometimes useful to enable it if
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
# License: MIT
|
|
2
2
|
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
|
|
3
3
|
|
|
4
|
-
"""A
|
|
4
|
+
"""A high-level interface for the dispatch API.
|
|
5
5
|
|
|
6
6
|
A small overview of the most important classes in this module:
|
|
7
7
|
|
|
8
|
-
* [Dispatcher][
|
|
9
|
-
* [Dispatch][
|
|
10
|
-
* [ActorDispatcher][
|
|
8
|
+
* [`Dispatcher`][.Dispatcher]: The entry point for the API.
|
|
9
|
+
* [`Dispatch`][.Dispatch]: A dispatch type with lots of useful extra functionality.
|
|
10
|
+
* [`ActorDispatcher`][.ActorDispatcher]: A service to manage other actors based on
|
|
11
11
|
incoming dispatches.
|
|
12
|
-
* [Created][
|
|
13
|
-
[Updated][
|
|
14
|
-
[Deleted][
|
|
12
|
+
* [`Created`][.Created],
|
|
13
|
+
[`Updated`][.Updated],
|
|
14
|
+
[`Deleted`][.Deleted]: Dispatch event types.
|
|
15
15
|
|
|
16
16
|
"""
|
|
17
17
|
|
{frequenz_dispatch-1.0.3 → frequenz_dispatch-1.0.4}/src/frequenz/dispatch/_actor_dispatcher.py
RENAMED
|
@@ -24,7 +24,7 @@ _logger = logging.getLogger(__name__)
|
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
class DispatchActorId(BaseId, str_prefix="DA"):
|
|
27
|
-
"""ID for a dispatch actor."""
|
|
27
|
+
"""An ID for a dispatch actor."""
|
|
28
28
|
|
|
29
29
|
def __init__(self, dispatch_id: DispatchId | int) -> None:
|
|
30
30
|
"""Initialize the DispatchActorId.
|
|
@@ -37,26 +37,26 @@ class DispatchActorId(BaseId, str_prefix="DA"):
|
|
|
37
37
|
|
|
38
38
|
@dataclass(frozen=True, kw_only=True)
|
|
39
39
|
class DispatchInfo:
|
|
40
|
-
"""
|
|
40
|
+
"""An event emitted when the dispatch changes."""
|
|
41
41
|
|
|
42
42
|
@property
|
|
43
43
|
@deprecated("'components' is deprecated, use 'target' instead.")
|
|
44
44
|
def components(self) -> TargetComponents:
|
|
45
|
-
"""
|
|
45
|
+
"""The target components.
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
Use [`target`][
|
|
47
|
+
Warning: Deprecated in v0.10.3
|
|
48
|
+
Use [`target`][..target] instead.
|
|
49
49
|
"""
|
|
50
50
|
return self.target
|
|
51
51
|
|
|
52
52
|
target: TargetComponents
|
|
53
|
-
"""
|
|
53
|
+
"""The target components."""
|
|
54
54
|
|
|
55
55
|
dry_run: bool
|
|
56
56
|
"""Whether this is a dry run."""
|
|
57
57
|
|
|
58
58
|
options: dict[str, Any]
|
|
59
|
-
"""
|
|
59
|
+
"""The additional options."""
|
|
60
60
|
|
|
61
61
|
_src: Dispatch
|
|
62
62
|
"""The dispatch that triggered this update."""
|
|
@@ -70,13 +70,13 @@ class DispatchInfo:
|
|
|
70
70
|
options: dict[str, Any],
|
|
71
71
|
_src: Dispatch,
|
|
72
72
|
) -> None:
|
|
73
|
-
"""Initialize
|
|
73
|
+
"""Initialize a new instance.
|
|
74
74
|
|
|
75
75
|
Args:
|
|
76
|
-
target:
|
|
76
|
+
target: The target components to be used.
|
|
77
77
|
components: Deprecated alias for `target`.
|
|
78
78
|
dry_run: Whether this is a dry run.
|
|
79
|
-
options:
|
|
79
|
+
options: The additional options.
|
|
80
80
|
_src: The dispatch that triggered this update.
|
|
81
81
|
|
|
82
82
|
Raises:
|
|
@@ -103,109 +103,109 @@ class DispatchInfo:
|
|
|
103
103
|
|
|
104
104
|
|
|
105
105
|
class ActorDispatcher(BackgroundService):
|
|
106
|
-
"""
|
|
107
|
-
|
|
108
|
-
Example
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
else:
|
|
152
|
-
await self._run_with_dispatch(other_recv)
|
|
153
|
-
|
|
154
|
-
async def _run_with_dispatch(self, other_recv: Receiver[Any]) -> None:
|
|
155
|
-
async for selected in select(self._dispatch_updates_receiver, other_recv):
|
|
156
|
-
if selected_from(selected, self._dispatch_updates_receiver):
|
|
157
|
-
self._update_dispatch_information(selected.message)
|
|
158
|
-
elif selected_from(selected, other_recv):
|
|
159
|
-
# do stuff
|
|
160
|
-
...
|
|
106
|
+
"""A helper class to manage actors based on dispatches.
|
|
107
|
+
|
|
108
|
+
Example:
|
|
109
|
+
```python
|
|
110
|
+
import os
|
|
111
|
+
import asyncio
|
|
112
|
+
from typing import Any, Self
|
|
113
|
+
from typing import override
|
|
114
|
+
from frequenz.dispatch import Dispatcher, ActorDispatcher, DispatchInfo
|
|
115
|
+
from frequenz.client.common.microgrid.components import ComponentCategory
|
|
116
|
+
from frequenz.channels import Receiver, Broadcast, select, selected_from
|
|
117
|
+
from frequenz.sdk.actor import Actor, run
|
|
118
|
+
|
|
119
|
+
class MyActor(Actor):
|
|
120
|
+
def __init__(
|
|
121
|
+
self,
|
|
122
|
+
*,
|
|
123
|
+
name: str | None = None,
|
|
124
|
+
) -> None:
|
|
125
|
+
super().__init__(name=name)
|
|
126
|
+
self._dispatch_updates_receiver: Receiver[DispatchInfo] | None = None
|
|
127
|
+
self._dry_run: bool = False
|
|
128
|
+
self._options: dict[str, Any] = {}
|
|
129
|
+
|
|
130
|
+
@classmethod
|
|
131
|
+
def new_with_dispatch(
|
|
132
|
+
cls,
|
|
133
|
+
initial_dispatch: DispatchInfo,
|
|
134
|
+
dispatch_updates_receiver: Receiver[DispatchInfo],
|
|
135
|
+
*,
|
|
136
|
+
name: str | None = None,
|
|
137
|
+
) -> Self:
|
|
138
|
+
self = cls(name=name)
|
|
139
|
+
self._dispatch_updates_receiver = dispatch_updates_receiver
|
|
140
|
+
self._update_dispatch_information(initial_dispatch)
|
|
141
|
+
return self
|
|
142
|
+
|
|
143
|
+
@override
|
|
144
|
+
async def _run(self) -> None:
|
|
145
|
+
other_recv: Receiver[Any] = ...
|
|
146
|
+
|
|
147
|
+
if self._dispatch_updates_receiver is None:
|
|
148
|
+
async for msg in other_recv:
|
|
149
|
+
# do stuff
|
|
150
|
+
...
|
|
161
151
|
else:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
152
|
+
await self._run_with_dispatch(other_recv)
|
|
153
|
+
|
|
154
|
+
async def _run_with_dispatch(self, other_recv: Receiver[Any]) -> None:
|
|
155
|
+
async for selected in select(self._dispatch_updates_receiver, other_recv):
|
|
156
|
+
if selected_from(selected, self._dispatch_updates_receiver):
|
|
157
|
+
self._update_dispatch_information(selected.message)
|
|
158
|
+
elif selected_from(selected, other_recv):
|
|
159
|
+
# do stuff
|
|
160
|
+
...
|
|
161
|
+
else:
|
|
162
|
+
assert False, f"Unexpected selected receiver: {selected}"
|
|
163
|
+
|
|
164
|
+
def _update_dispatch_information(self, dispatch_update: DispatchInfo) -> None:
|
|
165
|
+
print("Received update:", dispatch_update)
|
|
166
|
+
self._dry_run = dispatch_update.dry_run
|
|
167
|
+
self._options = dispatch_update.options
|
|
168
|
+
match dispatch_update.target:
|
|
169
|
+
case []:
|
|
170
|
+
print("Dispatch: Using all components")
|
|
171
|
+
case list() as ids if isinstance(ids[0], int):
|
|
172
|
+
component_ids = ids
|
|
173
|
+
case [ComponentCategory.BATTERY, *_]:
|
|
174
|
+
component_category = ComponentCategory.BATTERY
|
|
175
|
+
case unsupported:
|
|
176
|
+
print(
|
|
177
|
+
"Dispatch: Requested an unsupported selector %r, "
|
|
178
|
+
"but only component IDs or category BATTERY are supported.",
|
|
179
|
+
unsupported,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
async def main():
|
|
183
|
+
url = os.getenv("DISPATCH_API_URL", "grpc://dispatch.url.goes.here.example.com")
|
|
184
|
+
auth_key = os.getenv("DISPATCH_API_AUTH_KEY", "some-key")
|
|
185
|
+
sign_secret = os.getenv("DISPATCH_API_SIGN_SECRET")
|
|
186
|
+
|
|
187
|
+
microgrid_id = 1
|
|
188
|
+
|
|
189
|
+
async with Dispatcher(
|
|
190
|
+
microgrid_id=microgrid_id,
|
|
191
|
+
server_url=url,
|
|
192
|
+
auth_key=auth_key,
|
|
193
|
+
sign_secret=sign_secret,
|
|
194
|
+
) as dispatcher:
|
|
195
|
+
status_receiver = await dispatcher.new_running_state_event_receiver("EXAMPLE_TYPE")
|
|
196
|
+
|
|
197
|
+
managing_actor = ActorDispatcher(
|
|
198
|
+
actor_factory=MyActor.new_with_dispatch,
|
|
199
|
+
running_status_receiver=status_receiver,
|
|
200
|
+
)
|
|
201
201
|
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
await run(managing_actor)
|
|
203
|
+
```
|
|
204
204
|
"""
|
|
205
205
|
|
|
206
206
|
@dataclass(frozen=True, kw_only=True)
|
|
207
207
|
class ActorAndChannel:
|
|
208
|
-
"""
|
|
208
|
+
"""An actor and its dispatch update sender."""
|
|
209
209
|
|
|
210
210
|
actor: Actor
|
|
211
211
|
"""The actor."""
|
|
@@ -252,7 +252,11 @@ class ActorDispatcher(BackgroundService):
|
|
|
252
252
|
self._tasks.add(asyncio.create_task(self._run()))
|
|
253
253
|
|
|
254
254
|
async def _start_actor(self, dispatch: Dispatch) -> None:
|
|
255
|
-
"""Start the actor the given dispatch refers to.
|
|
255
|
+
"""Start the actor the given dispatch refers to.
|
|
256
|
+
|
|
257
|
+
Args:
|
|
258
|
+
dispatch: The dispatch to start the actor for.
|
|
259
|
+
"""
|
|
256
260
|
dispatch_update = DispatchInfo(
|
|
257
261
|
target=dispatch.target,
|
|
258
262
|
dry_run=dispatch.dry_run,
|
|
@@ -298,7 +302,7 @@ class ActorDispatcher(BackgroundService):
|
|
|
298
302
|
)
|
|
299
303
|
|
|
300
304
|
async def _stop_actor(self, stopping_dispatch: Dispatch, msg: str) -> None:
|
|
301
|
-
"""Stop
|
|
305
|
+
"""Stop the actor for the given dispatch.
|
|
302
306
|
|
|
303
307
|
Args:
|
|
304
308
|
stopping_dispatch: The dispatch that is stopping the actor.
|