Skip to content
Open
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
5 changes: 4 additions & 1 deletion taskiq/cli/scheduler/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ 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))
except Exception as e:
raise CronValueError(e) from e

try:
return pycron.is_now(cron_value, now)
Expand Down
18 changes: 18 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,21 @@ 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())


def test_is_cron_task_now_invalid_offset_string() -> None:
with pytest.raises(CronValueError):
is_cron_task_now(
cron_value="* * * * *",
now=datetime.now(timezone.utc),
offset="UTC+3",
)


def test_is_cron_task_now_unknown_timezone_name() -> None:
with pytest.raises(CronValueError):
is_cron_task_now(
cron_value="* * * * *",
now=datetime.now(timezone.utc),
offset="Europa/Madrid",
)
Loading