[fix][scheduler] status of scheduler task now saved again

This commit is contained in:
Tim Gröger 2024-10-15 13:37:23 +02:00
parent 607b29027b
commit cdb7958c57
2 changed files with 11 additions and 4 deletions

View File

@ -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()

View File

@ -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}")