Skip to content

Commit 8b2f24c

Browse files
committed
Use the same now for all in merge check
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 32440e0 commit 8b2f24c

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ dependencies = [
4040
# plugins.mkdocstrings.handlers.python.import)
4141
"frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2200",
4242
"frequenz-channels >= 1.6.1, < 2.0.0",
43-
"frequenz-client-dispatch >= 0.11.0, < 0.12.0",
43+
# "frequenz-client-dispatch >= 0.12.0, < 0.13.0",
44+
"frequenz-client-dispatch @ git+https://github.com/frequenz-floss/frequenz-client-dispatch-python@refs/pull/187/head",
4445
"frequenz-client-common >= 0.3.2, < 0.4.0",
4546
"frequenz-client-base >= 0.11.0, < 0.12.0",
4647
]

src/frequenz/dispatch/_dispatch.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,29 @@ def started(self) -> bool:
4343
Returns:
4444
True if the dispatch is started, False otherwise.
4545
"""
46+
now = datetime.now(tz=timezone.utc)
47+
return self.started_at(now)
48+
49+
def started_at(self, now: datetime) -> bool:
50+
"""Check if the dispatch has started.
51+
52+
A dispatch is considered started if the current time is after the start
53+
time but before the end time.
54+
55+
Recurring dispatches are considered started if the current time is after
56+
the start time of the last occurrence but before the end time of the
57+
last occurrence.
58+
59+
Params:
60+
now: time to use as now
61+
62+
Returns:
63+
True if the dispatch is started
64+
"""
4665
if self.deleted:
4766
return False
4867

49-
return super().started
68+
return super().started_at(now)
5069

5170
# noqa is needed because of a bug in pydoclint that makes it think a `return` without a return
5271
# value needs documenting

src/frequenz/dispatch/_merge_strategies.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import logging
77
from collections.abc import Mapping
8+
from datetime import datetime, timezone
89
from sys import maxsize
910
from typing import Any
1011

@@ -41,12 +42,14 @@ def filter(
4142
Keeps stop events only if no other dispatches matching the
4243
strategy's criteria are running.
4344
"""
44-
if dispatch.started:
45+
now = datetime.now(tz=timezone.utc)
46+
47+
if dispatch.started_at(now):
4548
_logger.debug("Keeping start event %s", dispatch.id)
4649
return True
4750

4851
other_dispatches_running = any(
49-
existing_dispatch.started
52+
existing_dispatch.started_at(now)
5053
for existing_dispatch in dispatches.values()
5154
if (
5255
self.identity(existing_dispatch) == self.identity(dispatch)

0 commit comments

Comments
 (0)