From dba93ae83afe0a91a7fd6a79f40eb81ab30a5e14 Mon Sep 17 00:00:00 2001 From: yzchen Date: Mon, 2 Mar 2026 11:19:45 +0800 Subject: [PATCH 1/2] cron: reload jobs store on each timer tick --- nanobot/cron/service.py | 2 ++ tests/test_cron_service.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/nanobot/cron/service.py b/nanobot/cron/service.py index c3864ae..811dc3b 100644 --- a/nanobot/cron/service.py +++ b/nanobot/cron/service.py @@ -226,6 +226,8 @@ class CronService: async def _on_timer(self) -> None: """Handle timer tick - run due jobs.""" + # Pick up external CLI/file changes before deciding due jobs. + self._load_store() if not self._store: return diff --git a/tests/test_cron_service.py b/tests/test_cron_service.py index 07e990a..2a36f4c 100644 --- a/tests/test_cron_service.py +++ b/tests/test_cron_service.py @@ -1,3 +1,5 @@ +import asyncio + import pytest from nanobot.cron.service import CronService @@ -28,3 +30,30 @@ def test_add_job_accepts_valid_timezone(tmp_path) -> None: assert job.schedule.tz == "America/Vancouver" assert job.state.next_run_at_ms is not None + + +@pytest.mark.asyncio +async def test_running_service_honors_external_disable(tmp_path) -> None: + store_path = tmp_path / "cron" / "jobs.json" + called: list[str] = [] + + async def on_job(job) -> None: + called.append(job.id) + + service = CronService(store_path, on_job=on_job) + job = service.add_job( + name="external-disable", + schedule=CronSchedule(kind="every", every_ms=200), + message="hello", + ) + await service.start() + try: + external = CronService(store_path) + updated = external.enable_job(job.id, enabled=False) + assert updated is not None + assert updated.enabled is False + + await asyncio.sleep(0.35) + assert called == [] + finally: + service.stop() From 9877195de57817101485f3effe7780f81c86f2d7 Mon Sep 17 00:00:00 2001 From: Re-bin Date: Mon, 2 Mar 2026 06:37:57 +0000 Subject: [PATCH 2/2] chore(cron): remove redundant timer comment --- nanobot/cron/service.py | 1 - 1 file changed, 1 deletion(-) diff --git a/nanobot/cron/service.py b/nanobot/cron/service.py index 811dc3b..1ed71f0 100644 --- a/nanobot/cron/service.py +++ b/nanobot/cron/service.py @@ -226,7 +226,6 @@ class CronService: async def _on_timer(self) -> None: """Handle timer tick - run due jobs.""" - # Pick up external CLI/file changes before deciding due jobs. self._load_store() if not self._store: return