diff --git a/flaschengeist/models/plugin.py b/flaschengeist/models/plugin.py index 4254cc8..0570490 100644 --- a/flaschengeist/models/plugin.py +++ b/flaschengeist/models/plugin.py @@ -1,6 +1,7 @@ from __future__ import annotations # TODO: Remove if python requirement is >= 3.12 (? PEP 563 is defered) -from typing import Any, List, Dict +from typing import Any, Dict, List + from sqlalchemy.orm.collections import attribute_mapped_collection from ..database import db @@ -68,7 +69,10 @@ class BasePlugin(db.Model): value: Value to be stored """ if value is None and name in self.__settings.keys(): - del self.__settings[name] + pl = self.__settings[name] + db.session.delete(pl) else: setting = self.__settings.setdefault(name, PluginSetting(plugin_id=self.id, name=name, value=None)) setting.value = value + db.session.add(setting) + db.session.commit() diff --git a/flaschengeist/plugins/scheduler.py b/flaschengeist/plugins/scheduler.py index ea26282..399c9fd 100644 --- a/flaschengeist/plugins/scheduler.py +++ b/flaschengeist/plugins/scheduler.py @@ -1,6 +1,7 @@ -from flask import Blueprint from datetime import datetime, timedelta +from flask import Blueprint + from flaschengeist import logger from flaschengeist.config import config from flaschengeist.plugins import Plugin @@ -66,15 +67,17 @@ class SchedulerPlugin(Plugin): changed = False now = datetime.now() - status = self.get_setting("status", default=dict()) + status: dict = self.get_setting("status", default=dict()) for id, task in _scheduled_tasks.items(): last_run = status.setdefault(id, now) + status[id] = last_run if last_run + task.interval <= now: logger.debug( f"Run task {id}, was scheduled for {last_run + task.interval}, next iteration: {now + task.interval}" ) task.function() + status[id] = now changed = True else: logger.debug(f"Skip task {id}, is scheduled for {last_run + task.interval}")