-
Notifications
You must be signed in to change notification settings - Fork 6
Initial structure #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a8ebfe8
Change structure to frequenz.dispatch
Marenz 0109674
Prepare dependencies for dispatch
Marenz 5f34f21
Fix labeler path
Marenz 0ab084e
Add highlevel dispatch interface
Marenz 4c7e08f
Ci: Reuse nox environment for crossbuilds
Marenz d646715
Use new type DispatchEvent for new/updated/deleted dispatches
Marenz d806154
Make poll interval configurable
Marenz 35cb8de
Explain functionality more in the documentation
Marenz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,6 @@ description = "A highlevel interface for the dispatch API" | |
readme = "README.md" | ||
license = { text = "MIT" } | ||
keywords = ["frequenz", "python", "actor", "frequenz-dispatch", "dispatch", "highlevel", "api"] | ||
# TODO(cookiecutter): Remove and add more classifiers if appropriate | ||
classifiers = [ | ||
"Development Status :: 3 - Alpha", | ||
"Intended Audience :: Developers", | ||
|
@@ -26,21 +25,27 @@ classifiers = [ | |
"Typing :: Typed", | ||
] | ||
requires-python = ">= 3.11, < 4" | ||
# TODO(cookiecutter): Remove and add more dependencies if appropriate | ||
dependencies = [ | ||
"python-dateutil >= 2.8.2, < 3.0", | ||
"typing-extensions == 4.10.0", | ||
# Make sure to update the version for cross-referencing also in the | ||
# mkdocs.yml file when changing the version here (look for the config key | ||
# plugins.mkdocstrings.handlers.python.import) | ||
"frequenz-sdk == 0.25.2", | ||
"frequenz-sdk == v1.0.0-rc5", | ||
"frequenz-channels == 1.0.0b2", | ||
"frequenz-dispatch-client @ git+https://github.com/frequenz-floss/frequenz-client-dispatch-python.git@00dcb3c", | ||
"frequenz-api-dispatch @ git+https://github.com/frequenz-floss/frequenz-api-dispatch.git@223315c", | ||
# "frequenz-api-dispatch >= 0.13.0, < 0.14", | ||
"frequenz-client-base >= 0.2.1, < 0.3.0", | ||
# Directly use unreleased commit until the first release | ||
"frequenz-client-common @ git+https://github.com/frequenz-floss/frequenz-client-common-python.git@5e6e7b7", | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
dynamic = ["version"] | ||
|
||
[[project.authors]] | ||
name = "Frequenz Energy-as-a-Service GmbH" | ||
email = "[email protected]" | ||
|
||
# TODO(cookiecutter): Remove and add more optional dependencies if appropriate | ||
[project.optional-dependencies] | ||
dev-flake8 = [ | ||
"flake8 == 7.0.0", | ||
|
@@ -64,11 +69,13 @@ dev-mkdocs = [ | |
dev-mypy = [ | ||
"mypy == 1.8.0", | ||
"types-Markdown == 3.5.0.20240129", | ||
"types-python-dateutil==2.8.19.20240311", | ||
# For checking the noxfile, docs/ script, and tests | ||
"frequenz-dispatch[dev-mkdocs,dev-noxfile,dev-pytest]", | ||
] | ||
dev-noxfile = [ | ||
"nox == 2023.4.22", | ||
"uv == 0.1.14", | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"nox == 2024.3.02", | ||
"frequenz-repo-config[lib] == 0.9.1", | ||
] | ||
dev-pylint = [ | ||
|
@@ -82,6 +89,7 @@ dev-pytest = [ | |
"pytest-mock == 3.12.0", | ||
"pytest-asyncio == 0.23.5", | ||
"async-solipsism == 0.5", | ||
"time-machine == 2.14.0", | ||
] | ||
dev = [ | ||
"frequenz-dispatch[dev-mkdocs,dev-flake8,dev-formatting,dev-mkdocs,dev-mypy,dev-noxfile,dev-pylint,dev-pytest]", | ||
|
@@ -159,11 +167,15 @@ namespace_packages = true | |
# used but getting the original ignored error when removing the type: ignore. | ||
# See for example: https://github.com/python/mypy/issues/2960 | ||
#no_incremental = true | ||
packages = ["frequenz.actor.dispatch"] | ||
packages = ["frequenz.dispatch"] | ||
strict = true | ||
|
||
[[tool.mypy.overrides]] | ||
module = ["mkdocs_macros.*"] | ||
module = [ | ||
"mkdocs_macros.*", | ||
"async_solipsism", | ||
"async_solipsism.*", | ||
] | ||
ignore_missing_imports = true | ||
|
||
[tool.setuptools_scm] | ||
|
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# License: MIT | ||
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH | ||
|
||
"""A highlevel interface for the dispatch API.""" | ||
|
||
import grpc.aio | ||
from frequenz.channels import Broadcast, Receiver | ||
from frequenz.client.dispatch.types import Dispatch | ||
|
||
from frequenz.dispatch.actor import DispatchActor, DispatchEvent | ||
|
||
__all__ = ["Dispatcher"] | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class Dispatcher: | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""A highlevel interface for the dispatch API. | ||
|
||
This class provides a highlevel interface to the dispatch API. | ||
It provides two channels: | ||
|
||
One that sends a dispatch event message whenever a dispatch is created, updated or deleted. | ||
|
||
The other sends a dispatch message whenever a dispatch is ready to be | ||
executed according to the schedule. | ||
|
||
allows to receive new dispatches and ready dispatches. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion:
I would also suggest adding a small blurb about the difference between the two. |
||
|
||
Example: | ||
```python | ||
from frequenz.dispatch import Dispatcher | ||
|
||
async def run(): | ||
dispatcher = Dispatcher(API_CONNECTION_INFO) | ||
dispatcher.start() # this will start the actor | ||
dispatch_arrived = dispatcher.new_dispatches().new_receiver() | ||
dispatch_ready = dispatcher.ready_dispatches().new_receiver() | ||
``` | ||
""" | ||
|
||
def __init__( | ||
self, microgrid_id: int, grpc_channel: grpc.aio.Channel, svc_addr: str | ||
): | ||
"""Initialize the dispatcher. | ||
|
||
Args: | ||
microgrid_id: The microgrid id. | ||
grpc_channel: The gRPC channel. | ||
svc_addr: The service address. | ||
""" | ||
self._ready_channel = Broadcast[Dispatch]("ready_dispatches") | ||
self._updated_channel = Broadcast[DispatchEvent]("new_dispatches") | ||
self._actor = DispatchActor( | ||
microgrid_id, | ||
grpc_channel, | ||
svc_addr, | ||
self._updated_channel.new_sender(), | ||
self._ready_channel.new_sender(), | ||
) | ||
|
||
async def start(self) -> None: | ||
"""Start the actor.""" | ||
self._actor.start() | ||
|
||
def updated_dispatches(self) -> Receiver[DispatchEvent]: | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Return new, updated or deleted dispatches receiver. | ||
|
||
Returns: | ||
A new receiver for new dispatches. | ||
""" | ||
return self._updated_channel.new_receiver() | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def ready_dispatches(self) -> Receiver[Dispatch]: | ||
llucax marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Return ready dispatches receiver. | ||
|
||
Returns: | ||
A new receiver for ready dispatches. | ||
""" | ||
return self._ready_channel.new_receiver() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.