Skip to content

Commit d04f85d

Browse files
authored
move from cronexpr to cronsim (#1)
* Replace cronexpr with cronsim for cron scheduling The cronexpr package is replaced by cronsim for computing next fire times. This also bumps the project version to 0.8.0, updates the build system requirement.
1 parent 3c12638 commit d04f85d

4 files changed

Lines changed: 14 additions & 49 deletions

File tree

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repos:
3232
rev: v1.18.2
3333
hooks:
3434
- id: mypy
35-
additional_dependencies: [ "types-redis", "fastapi", "pydantic"]
35+
additional_dependencies: [ "types-redis", "fastapi", "pydantic", "cronsim"]
3636
args: ["--scripts-are-modules"]
3737

3838
- repo: https://github.com/astral-sh/uv-pre-commit

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "fastapi-task-manager"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
description = "A task manager for Fastapi. Robust Scheduling, Distributed Safety"
55
readme = "README.md"
66
authors = [
@@ -31,14 +31,14 @@ classifiers = [
3131
"Operating System :: OS Independent",
3232
]
3333
dependencies = [
34-
"cronexpr>=0.30.0",
34+
"cronsim>=2.7",
3535
"fastapi>=0.115.13",
3636
"pydantic>=2.11.7",
3737
"redis>=6.2.0",
3838
]
3939

4040
[build-system]
41-
requires = ["uv_build>=0.7.20,<0.9.0"]
41+
requires = ["uv_build>=0.9.0,<0.10.0"]
4242
build-backend = "uv_build"
4343

4444
[[tool.uv.index]]

src/fastapi_task_manager/runner.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import TYPE_CHECKING
77
from uuid import uuid4
88

9-
from cronexpr import next_fire
9+
from cronsim import CronSim
1010
from redis.asyncio import Redis
1111

1212
from fastapi_task_manager import TaskGroup
@@ -142,7 +142,9 @@ async def _run_task(self, task_group: TaskGroup, task: Task) -> None: # noqa: P
142142
if redis_uuid_b.decode("utf-8") != self._uuid:
143143
return
144144

145-
next_run = next_fire(task.expression)
145+
local_date = datetime.now(timezone.utc)
146+
next_run = next(CronSim(task.expression, local_date))
147+
146148
await self._redis_client.set(
147149
self._task_manager.config.app_name + "_" + task_group.name + "_" + task.name + "_next_run",
148150
next_run.timestamp(),

uv.lock

Lines changed: 6 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)