diff --git a/api/ovkiosk/dav_file.py b/api/ovkiosk/dav_file.py index a279bc8..0d909ff 100644 --- a/api/ovkiosk/dav_file.py +++ b/api/ovkiosk/dav_file.py @@ -11,6 +11,8 @@ _logger = logging.getLogger(__name__) class DavFile: __instances = None + __scheduler = None + __job = None def __init__(self, client: Client, path: Any) -> None: self.__resource: Resource = client.resource(path) @@ -31,21 +33,29 @@ class DavFile: self.__resource.write_to(self.__buffer) @classmethod - def refresh(cls, refresh_interval: int = 5) -> AsyncIOScheduler: - scheduler = AsyncIOScheduler() + def refresh(cls, refresh_interval: int = 60): + if cls.__job is not None: + cls.__scheduler.reschedule_job( + job_id=cls.__name__, + trigger="interval", + seconds=refresh_interval, + ) + return def tick() -> None: for davfile in DavFile.__instances: davfile.update() - scheduler.add_job(tick) - scheduler.add_job( - tick, "interval", + cls.__scheduler = AsyncIOScheduler() + cls.__scheduler.start() + + cls.__scheduler.add_job(tick) + cls.__job = cls.__scheduler.add_job( + tick, + id=cls.__name__, + trigger="interval", seconds=refresh_interval, ) - scheduler.start() - - return scheduler @property def bytes(self) -> bytes: