File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ dependencies = [
40
40
# plugins.mkdocstrings.handlers.python.import)
41
41
" frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2200" ,
42
42
" 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" ,
44
45
" frequenz-client-common >= 0.3.2, < 0.4.0" ,
45
46
" frequenz-client-base >= 0.11.0, < 0.12.0" ,
46
47
]
Original file line number Diff line number Diff line change @@ -43,10 +43,29 @@ def started(self) -> bool:
43
43
Returns:
44
44
True if the dispatch is started, False otherwise.
45
45
"""
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
+ """
46
65
if self .deleted :
47
66
return False
48
67
49
- return super ().started
68
+ return super ().started_at ( now )
50
69
51
70
# noqa is needed because of a bug in pydoclint that makes it think a `return` without a return
52
71
# value needs documenting
Original file line number Diff line number Diff line change 5
5
6
6
import logging
7
7
from collections .abc import Mapping
8
+ from datetime import datetime , timezone
8
9
from sys import maxsize
9
10
from typing import Any
10
11
@@ -41,12 +42,14 @@ def filter(
41
42
Keeps stop events only if no other dispatches matching the
42
43
strategy's criteria are running.
43
44
"""
44
- if dispatch .started :
45
+ now = datetime .now (tz = timezone .utc )
46
+
47
+ if dispatch .started_at (now ):
45
48
_logger .debug ("Keeping start event %s" , dispatch .id )
46
49
return True
47
50
48
51
other_dispatches_running = any (
49
- existing_dispatch .started
52
+ existing_dispatch .started_at ( now )
50
53
for existing_dispatch in dispatches .values ()
51
54
if (
52
55
self .identity (existing_dispatch ) == self .identity (dispatch )
You can’t perform that action at this time.
0 commit comments