Skip to content

Your lightweight open-source personal agent.

cron: reload jobs store on each timer tick

yzchendba93ae83afe
diff --git a/nanobot/cron/service.py b/nanobot/cron/service.py
index c3864aeb9..811dc3ba8 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 07e990a0d..2a36f4c39 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
+
+
+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()