From cdb7958c57226145bd427e047981f8f0894c8fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 15 Oct 2024 13:37:23 +0200 Subject: [PATCH] [fix][scheduler] status of scheduler task now saved again --- flaschengeist/models/plugin.py | 8 ++++++-- flaschengeist/plugins/scheduler.py | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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}")