A highlevel interface for the dispatch API
Project description
Dispatch Highlevel Interface
Introduction
A highlevel interface for the dispatch API.
See the documentation for more information.
Usage
The Dispatcher
class, the main entry point for the API, provides two channels:
- Lifecycle events: A channel that sends a message whenever a [Dispatch][frequenz.dispatch.Dispatch] is created, updated or deleted.
- Running status change: Sends a dispatch message whenever a dispatch is ready to be executed according to the schedule or the running status of the dispatch changed in a way that could potentially require the actor to start, stop or reconfigure itself.
Example using the running status change channel
import os
from frequenz.dispatch import Dispatcher, RunningState
from unittest.mock import MagicMock
async def run():
url = os.getenv("DISPATCH_API_URL", "grpc://fz-0004.frequenz.io:50051")
key = os.getenv("DISPATCH_API_KEY", "some-key")
microgrid_id = 1
dispatcher = Dispatcher(
microgrid_id=microgrid_id,
server_url=url,
key=key
)
await dispatcher.start()
actor = MagicMock() # replace with your actor
changed_running_status_rx = dispatcher.running_status_change.new_receiver()
async for dispatch in changed_running_status_rx:
match dispatch.running("DEMO_TYPE"):
case RunningState.RUNNING:
print(f"Executing dispatch {dispatch.id}, due on {dispatch.start_time}")
if actor.is_running:
actor.reconfigure(
components=dispatch.target,
run_parameters=dispatch.payload, # custom actor parameters
dry_run=dispatch.dry_run,
until=dispatch.until,
) # this will reconfigure the actor
else:
# this will start a new actor with the given components
# and run it for the duration of the dispatch
actor.start(
components=dispatch.target,
run_parameters=dispatch.payload, # custom actor parameters
dry_run=dispatch.dry_run,
until=dispatch.until,
)
case RunningState.STOPPED:
actor.stop() # this will stop the actor
case RunningState.DIFFERENT_TYPE:
pass # dispatch not for this type
Supported Platforms
The following platforms are officially supported (tested):
- Python: 3.11
- Operating System: Ubuntu Linux 20.04
- Architectures: amd64, arm64
Contributing
If you want to know how to build this project and contribute to it, please check out the Contributing Guide.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file frequenz-dispatch-0.4.0.tar.gz
.
File metadata
- Download URL: frequenz-dispatch-0.4.0.tar.gz
- Upload date:
- Size: 17.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 952fcf59f838680c23c31b9994e56765ff159782a9b283623918cf81d33d9438 |
|
MD5 | 59497ac3dcac0d264a82e551d4411e84 |
|
BLAKE2b-256 | b22265f0f76341aaaa4b97a037e6b0898a6ddd2960a564f311650f1c5ac49b2d |
Provenance
The following attestation bundles were made for frequenz-dispatch-0.4.0.tar.gz
:
Publisher:
ci.yaml
on frequenz-floss/frequenz-dispatch-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
frequenz_dispatch-0.4.0.tar.gz
- Subject digest:
952fcf59f838680c23c31b9994e56765ff159782a9b283623918cf81d33d9438
- Sigstore transparency entry: 149919699
- Sigstore integration time:
- Predicate type:
File details
Details for the file frequenz_dispatch-0.4.0-py3-none-any.whl
.
File metadata
- Download URL: frequenz_dispatch-0.4.0-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2dddd8544bd2b4f27ed8af910a3d60a9aaa43a86a3590f827e9c271207fc531f |
|
MD5 | 54271ed27405a695b35cdfa5727cdb38 |
|
BLAKE2b-256 | 0c989d2982fbc1a914db18f0f7f6fa4fb8fcaa5ac05a3d17a772fb8c04795a06 |
Provenance
The following attestation bundles were made for frequenz_dispatch-0.4.0-py3-none-any.whl
:
Publisher:
ci.yaml
on frequenz-floss/frequenz-dispatch-python
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
frequenz_dispatch-0.4.0-py3-none-any.whl
- Subject digest:
2dddd8544bd2b4f27ed8af910a3d60a9aaa43a86a3590f827e9c271207fc531f
- Sigstore transparency entry: 149919706
- Sigstore integration time:
- Predicate type: