From f4fa0ee4d0de9bf038923e42779af1d1282cc7d8 Mon Sep 17 00:00:00 2001 From: MoeexT Date: Wed, 25 Feb 2026 17:07:03 +0800 Subject: [PATCH 1/2] :bug: create task with local time-zone --- .../app/module/shared/schedule/scheduler.py | 15 +++++++++++---- runtime/datamate-python/pyproject.toml | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/datamate-python/app/module/shared/schedule/scheduler.py b/runtime/datamate-python/app/module/shared/schedule/scheduler.py index 1bf161b37..a6bf00424 100644 --- a/runtime/datamate-python/app/module/shared/schedule/scheduler.py +++ b/runtime/datamate-python/app/module/shared/schedule/scheduler.py @@ -6,20 +6,26 @@ from apscheduler.triggers.cron import CronTrigger from app.core.logging import get_logger +import pytz logger = get_logger(__name__) class Scheduler: - def __init__(self, name: str = "scheduler") -> None: + def __init__(self, name: str = "scheduler", timezone: Optional[str] = None) -> None: self._name = name self._scheduler: Optional[AsyncIOScheduler] = None + # 使用指定的时区,如果没有指定则使用本地时区 + self._timezone = pytz.timezone(timezone) if timezone else None def start(self) -> AsyncIOScheduler: if self._scheduler is None: - self._scheduler = AsyncIOScheduler() + # 配置调度器使用本地时区 + from tzlocal import get_localzone + local_tz = get_localzone() + self._scheduler = AsyncIOScheduler(timezone=local_tz) self._scheduler.start() - logger.info(f"{self._name} started") + logger.info(f"{self._name} started with timezone: {local_tz}") return self._scheduler def shutdown(self) -> None: @@ -38,7 +44,8 @@ def add_cron_job( **job_kwargs: Any, ) -> None: scheduler = self._get_scheduler() - trigger = CronTrigger.from_crontab(cron_expression) + # 使用调度器的时区创建 CronTrigger + trigger = CronTrigger.from_crontab(cron_expression, timezone=scheduler.timezone) scheduler.add_job( func, trigger=trigger, diff --git a/runtime/datamate-python/pyproject.toml b/runtime/datamate-python/pyproject.toml index c29a95a74..a7004f832 100644 --- a/runtime/datamate-python/pyproject.toml +++ b/runtime/datamate-python/pyproject.toml @@ -37,6 +37,7 @@ dependencies = [ "lightrag-hku (==1.4.9.8)", "pytest (>=9.0.2,<10.0.0)", "apscheduler (>=3.11.2,<4.0.0)", + "tzlocal (>=5.2,<6.0)", ] From 4ee7c3e2c8994d163c950634b7ce5280bda205cc Mon Sep 17 00:00:00 2001 From: MoeexT Date: Thu, 26 Feb 2026 16:26:01 +0800 Subject: [PATCH 2/2] :pushpin: update poetry.lock --- runtime/datamate-python/poetry.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/datamate-python/poetry.lock b/runtime/datamate-python/poetry.lock index 5c4db4a1a..b3290dd35 100644 --- a/runtime/datamate-python/poetry.lock +++ b/runtime/datamate-python/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 2.2.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 2.3.2 and should not be changed by hand. [[package]] name = "aiofiles" @@ -1604,7 +1604,7 @@ files = [ [package.dependencies] attrs = ">=22.2.0" -jsonschema-specifications = ">=2023.03.6" +jsonschema-specifications = ">=2023.3.6" referencing = ">=0.28.4" rpds-py = ">=0.25.0" @@ -5474,9 +5474,9 @@ files = [ ] [package.extras] -cffi = ["cffi (>=1.17,<2.0) ; platform_python_implementation != \"PyPy\" and python_version < \"3.14\"", "cffi (>=2.0.0b) ; platform_python_implementation != \"PyPy\" and python_version >= \"3.14\""] +cffi = ["cffi (>=1.17,<2.0) ; platform_python_implementation != \"PyPy\" and python_version < \"3.14\"", "cffi (>=2.0.0b0) ; platform_python_implementation != \"PyPy\" and python_version >= \"3.14\""] [metadata] lock-version = "2.1" python-versions = ">=3.12,<4.0.0" -content-hash = "3a84e7e5ec3874279a429a3b609f5d9c32794c8d0e422b2f93e1dbf3f24fc38e" +content-hash = "6c9fb82271c16a05eda4edf9bae73eeecf9044f6a0421370eefa09d31c1b1875"