From 3ffc72f0652d7e420f62b21f1a6d1996303a4294 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Wed, 31 Aug 2022 02:15:48 +0000 Subject: [PATCH] don't expose scheduler --- api/ovkiosk/dav_file.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) 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: