Replies: 2 comments
-
I was able to make an attempt at adding a quarterhour timer. I suspect there is an easier way to do this? Adding the following: components: ClassVar[Tuple[str]] = ("year", "month", "week", "day", "hour", "quarterhour", "minute", "second", "microsecond") and then adding this to the test code. @dataclass(frozen=True, init=False)
class TimeOfQuarterHour(AnchoredInterval):
"""Time interval anchored to quarter hour cycle of a clock
min: 0 minutes, 0 seconds, 0 microsecond
max: 14 minutes, 59 seconds, 999999 microsecond
Example:
# From 9 past to 14 past
TimeOfQuarterHour("00:09", "00:14")
"""
_scope: ClassVar[str] = "quarterhour"
_scope_max: ClassVar[int] = to_microseconds(minute=15)
_unit_resolution: ClassVar[int] = to_microseconds(minute=1)
_unit_names: ClassVar[List[str]] = [f"00:{i:02d}" for i in range(15)] # 00:00, 00:14 etc. till 00:14
def anchor_int(self, i, **kwargs):
if not 0 <= i <= 14:
raise ValueError(f"Invalid minute: {i}. Minute is from 0 to 14")
return super().anchor_int(i, **kwargs)
def anchor_str(self, s, **kwargs):
# ie. 12:30.123
res = re.search(r"(?P<minute>[0-9][0-9]):(?P<second>[0-9][0-9])([.](?P<microsecond>[0-9]{0,6}))?", s, flags=re.IGNORECASE)
if res:
res = res.groupdict()
if res["microsecond"] is not None:
res["microsecond"] = res["microsecond"].ljust(6, "0")
return to_microseconds(**{key: int(val) for key, val in res.items() if val is not None})
raise ValueError(f"Invalid value: {repr(s)}")
quarterhourly = TimeCondWrapper(TaskExecutable, TimeOfQuarterHour) This seems fine except for having to modify a file inside the library, but maybe there is a way around it that I am not seeing. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Another option I came up with that could works for hour and minute. @app.task(time_of_minute.at(9) | time_of_minute.at(14) | time_of_minute.at(24) | time_of_minute.at(29) | time_of_minute.at(39) | time_of_minute.at(44) | time_of_minute.at(54) | time_of_minute.at(59)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to make a custom window for the timer. e.g. Execute a task every 9th and 14th minute in a 15 minute window?
Beta Was this translation helpful? Give feedback.
All reactions