Fix scheduler breaking DB encapsulation for one-time task disabling

Add Database.disable_task() public method and replace direct _conn
access in scheduler._run_due_tasks().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cora-start
PeninsulaInd 2026-02-16 18:09:38 -06:00
parent ff3114b515
commit 76c0711704
2 changed files with 8 additions and 4 deletions

View File

@ -178,6 +178,13 @@ class Database:
)
self._conn.commit()
def disable_task(self, task_id: int):
"""Disable a scheduled task (e.g. after a one-time task has run)."""
self._conn.execute(
"UPDATE scheduled_tasks SET enabled = 0 WHERE id = ?", (task_id,)
)
self._conn.commit()
def log_task_run(self, task_id: int, result: str | None = None, error: str | None = None):
now = _now()
self._conn.execute(

View File

@ -97,10 +97,7 @@ class Scheduler:
schedule = task["schedule"]
if schedule.startswith("once:"):
# One-time task, disable it
self.db._conn.execute(
"UPDATE scheduled_tasks SET enabled = 0 WHERE id = ?", (task["id"],)
)
self.db._conn.commit()
self.db.disable_task(task["id"])
else:
# Cron schedule - calculate next run
now = datetime.now(timezone.utc)