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
parent
ff3114b515
commit
76c0711704
|
|
@ -178,6 +178,13 @@ class Database:
|
||||||
)
|
)
|
||||||
self._conn.commit()
|
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):
|
def log_task_run(self, task_id: int, result: str | None = None, error: str | None = None):
|
||||||
now = _now()
|
now = _now()
|
||||||
self._conn.execute(
|
self._conn.execute(
|
||||||
|
|
|
||||||
|
|
@ -97,10 +97,7 @@ class Scheduler:
|
||||||
schedule = task["schedule"]
|
schedule = task["schedule"]
|
||||||
if schedule.startswith("once:"):
|
if schedule.startswith("once:"):
|
||||||
# One-time task, disable it
|
# One-time task, disable it
|
||||||
self.db._conn.execute(
|
self.db.disable_task(task["id"])
|
||||||
"UPDATE scheduled_tasks SET enabled = 0 WHERE id = ?", (task["id"],)
|
|
||||||
)
|
|
||||||
self.db._conn.commit()
|
|
||||||
else:
|
else:
|
||||||
# Cron schedule - calculate next run
|
# Cron schedule - calculate next run
|
||||||
now = datetime.now(timezone.utc)
|
now = datetime.now(timezone.utc)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue