don't expose scheduler
This commit is contained in:
parent
b040ede864
commit
3ffc72f065
1 changed files with 18 additions and 8 deletions
|
@ -11,6 +11,8 @@ _logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
class DavFile:
|
class DavFile:
|
||||||
__instances = None
|
__instances = None
|
||||||
|
__scheduler = None
|
||||||
|
__job = None
|
||||||
|
|
||||||
def __init__(self, client: Client, path: Any) -> None:
|
def __init__(self, client: Client, path: Any) -> None:
|
||||||
self.__resource: Resource = client.resource(path)
|
self.__resource: Resource = client.resource(path)
|
||||||
|
@ -31,21 +33,29 @@ class DavFile:
|
||||||
self.__resource.write_to(self.__buffer)
|
self.__resource.write_to(self.__buffer)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def refresh(cls, refresh_interval: int = 5) -> AsyncIOScheduler:
|
def refresh(cls, refresh_interval: int = 60):
|
||||||
scheduler = AsyncIOScheduler()
|
if cls.__job is not None:
|
||||||
|
cls.__scheduler.reschedule_job(
|
||||||
|
job_id=cls.__name__,
|
||||||
|
trigger="interval",
|
||||||
|
seconds=refresh_interval,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
def tick() -> None:
|
def tick() -> None:
|
||||||
for davfile in DavFile.__instances:
|
for davfile in DavFile.__instances:
|
||||||
davfile.update()
|
davfile.update()
|
||||||
|
|
||||||
scheduler.add_job(tick)
|
cls.__scheduler = AsyncIOScheduler()
|
||||||
scheduler.add_job(
|
cls.__scheduler.start()
|
||||||
tick, "interval",
|
|
||||||
|
cls.__scheduler.add_job(tick)
|
||||||
|
cls.__job = cls.__scheduler.add_job(
|
||||||
|
tick,
|
||||||
|
id=cls.__name__,
|
||||||
|
trigger="interval",
|
||||||
seconds=refresh_interval,
|
seconds=refresh_interval,
|
||||||
)
|
)
|
||||||
scheduler.start()
|
|
||||||
|
|
||||||
return scheduler
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bytes(self) -> bytes:
|
def bytes(self) -> bytes:
|
||||||
|
|
Loading…
Reference in a new issue