From 76c071170453feac60eb579a36e9aea095a2024c Mon Sep 17 00:00:00 2001 From: PeninsulaInd Date: Mon, 16 Feb 2026 18:09:38 -0600 Subject: [PATCH] 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 --- cheddahbot/db.py | 7 +++++++ cheddahbot/scheduler.py | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cheddahbot/db.py b/cheddahbot/db.py index e56908e..e15fb67 100644 --- a/cheddahbot/db.py +++ b/cheddahbot/db.py @@ -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( diff --git a/cheddahbot/scheduler.py b/cheddahbot/scheduler.py index 94ed849..77a6025 100644 --- a/cheddahbot/scheduler.py +++ b/cheddahbot/scheduler.py @@ -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)