Skip to content

Commit 15e619f

Browse files
authored
Send stop signal when duration is reached (#53)
- **Reset release notes** - **Send STOPPED message when duration is reached**
2 parents 05f333b + 46d5b17 commit 15e619f

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66

77
## Upgrading
88

9-
- The dispatch high level interface now depends on `frequenz-sdk` version `v1.0.0-rc900`.
10-
- We are now using the version `0.6.0` of the underlying `frequenz-client-dispatch` client library.
11-
- The init parameter of the `Dispatcher` class has been changed to accept a `server_url` instead.
9+
* `Dispatcher.running_state_change` now also sends a message when the duration specified in the dispatch has passed. If no duration is specified, no STOPPED message will be sent.
1210

1311
## New Features
1412

15-
* Using the new dispatch client, we now have support for pagination in the dispatch list request.
16-
* The new client version also supports streaming, however it is not yet used internally in the high level interface.
13+
<!-- Here goes the main new features and examples or instructions on how to use them -->
1714

1815
## Bug Fixes
1916

20-
- Fix documentation cross-linking to the `frequenz-client-dispatch` package.
17+
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

src/frequenz/dispatch/actor.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,20 @@ def next_run_info() -> tuple[datetime, datetime] | None:
183183
_logger.info("Dispatch %s scheduled for %s", dispatch.id, next_time)
184184
await asyncio.sleep((next_time - now).total_seconds())
185185

186-
_logger.info("Dispatch ready: %s", dispatch)
186+
_logger.info("Dispatch %s executing...", dispatch)
187187
await self._running_state_change_sender.send(dispatch)
188188

189-
_logger.info("Dispatch finished: %s", dispatch)
189+
# Wait for the duration of the dispatch if set
190+
if dispatch.duration:
191+
_logger.info(
192+
"Dispatch %s running for %s", dispatch.id, dispatch.duration
193+
)
194+
await asyncio.sleep(dispatch.duration.total_seconds())
195+
196+
_logger.info("Dispatch %s runtime duration reached", dispatch.id)
197+
await self._running_state_change_sender.send(dispatch)
198+
199+
_logger.info("Dispatch completed: %s", dispatch)
190200
self._scheduled.pop(dispatch.id)
191201

192202
def _running_state_change(

tests/test_frequenz_dispatch.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,15 @@ async def test_dispatch_schedule(
236236
fake_time.shift(next_run - _now() - timedelta(seconds=1))
237237
await asyncio.sleep(1)
238238

239+
# Expect notification of the dispatch being ready to run
239240
ready_dispatch = await actor_env.ready_dispatches.receive()
240241

241242
assert ready_dispatch == dispatch
243+
244+
# Shift time to the end of the dispatch
245+
fake_time.shift(dispatch.duration + timedelta(seconds=1))
246+
await asyncio.sleep(1)
247+
248+
# Expect notification to stop the dispatch
249+
done_dispatch = await actor_env.ready_dispatches.receive()
250+
assert done_dispatch == dispatch

0 commit comments

Comments
 (0)