Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->
* The dispatcher offers two new parameters to control the client's call and stream timeout:
- `call_timeout`: The maximum time to wait for a response from the client.
- `stream_timeout`: The maximum time to wait before restarting a stream.

## Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies = [
# plugins.mkdocstrings.handlers.python.import)
"frequenz-sdk >= 1.0.0-rc1900, < 1.0.0-rc2100",
"frequenz-channels >= 1.6.1, < 2.0.0",
"frequenz-client-dispatch >= 0.10.1, < 0.11.0",
"frequenz-client-dispatch >= 0.10.2, < 0.11.0",
]
dynamic = ["version"]

Expand Down
12 changes: 11 additions & 1 deletion src/frequenz/dispatch/_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,33 @@ async def run():
```
"""

# pylint: disable-next=too-many-arguments
def __init__(
self,
*,
microgrid_id: int,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to do with this PR but I wonder if there is a reason why you need to pass the microgrid_id when creating the client. For edge clients this makes sense, but for cloud clients? You need to create one client per microgrid? This feels weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.. this is an edge client?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, well. We need to know the id we want dispatches for, that's why we need the microgrid id.

server_url: str,
key: str,
call_timeout: timedelta = timedelta(seconds=60),
stream_timeout: timedelta = timedelta(minutes=5),
):
"""Initialize the dispatcher.

Args:
microgrid_id: The microgrid id.
server_url: The URL of the dispatch service.
key: The key to access the service.
call_timeout: The timeout for API calls.
stream_timeout: The timeout for streaming API calls.
"""
super().__init__()

self._client = DispatchApiClient(server_url=server_url, key=key)
self._client = DispatchApiClient(
server_url=server_url,
key=key,
call_timeout=call_timeout,
stream_timeout=stream_timeout,
)
self._bg_service = DispatchScheduler(
microgrid_id,
self._client,
Expand Down
1 change: 1 addition & 0 deletions tests/test_frequenz_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ async def test_dispatch_schedule(
active=True,
duration=timedelta(seconds=10),
type="TEST_TYPE",
recurrence=RecurrenceRule(),
)
await test_env.client.create(**to_create_params(test_env.microgrid_id, sample))
# Get the initial dispatch state from the client to use as a base for comparison
Expand Down
11 changes: 10 additions & 1 deletion tests/test_managing_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,18 @@ async def test_manage_abstraction(
class MyFakeClient(FakeClient):
"""Fake client for testing."""

def __init__(self, *, server_url: str, key: str):
def __init__(
self,
*,
server_url: str,
key: str,
call_timeout: timedelta,
stream_timeout: timedelta,
) -> None:
assert server_url
assert key
assert call_timeout
assert stream_timeout
super().__init__()

mid = 1
Expand Down
Loading