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)