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
10 changes: 8 additions & 2 deletions taskiq/cli/scheduler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from datetime import datetime, timedelta, timezone
from logging import basicConfig, getLogger
from typing import Any, TypeAlias
from zoneinfo import ZoneInfo
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError

import pycron

Expand Down Expand Up @@ -99,7 +99,13 @@ def is_cron_task_now(
# If timezone was specified as string we convert it timezone
# offset and then apply.
elif offset and isinstance(offset, str):
now = now.astimezone(ZoneInfo(offset))
try:
now = now.astimezone(ZoneInfo(offset))
# ZoneInfoNotFoundError for unknown keys, ModuleNotFoundError
# for systems without timezone data available (e.g. missing
# tzdata on Windows).
except (ZoneInfoNotFoundError, ModuleNotFoundError) as e:
raise CronValueError(e) from e

try:
return pycron.is_now(cron_value, now)
Expand Down
13 changes: 13 additions & 0 deletions tests/cli/scheduler/test_is_cron_task_now.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,16 @@ def test_is_cron_task_now(
def test_is_cron_task_now_invalid_cron() -> None:
with pytest.raises(CronValueError):
is_cron_task_now("invalid cron", datetime.now())


@pytest.mark.parametrize(
"offset",
["UTC+3", "Europa/Madrid"],
)
def test_is_cron_task_now_invalid_offset_string(offset: str) -> None:
with pytest.raises(CronValueError):
is_cron_task_now(
cron_value="* * * * *",
now=datetime.now(timezone.utc),
offset=offset,
)
Loading