From 3b418daf684f01a126a56b58c83120af5914f576 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 5 Oct 2025 07:24:22 +0300 Subject: Remove the redundant scheduler class This allows fetching the database every time, ensuring any updates to the database between fetches as captured. --- components/subscriptions/main.py | 9 --------- components/subscriptions/typing.py | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'components') diff --git a/components/subscriptions/main.py b/components/subscriptions/main.py index 36e6d15..afd1d54 100644 --- a/components/subscriptions/main.py +++ b/components/subscriptions/main.py @@ -6,13 +6,10 @@ from bson.objectid import ObjectId from feedparser import parse # type: ignore from pymongo.collection import Collection from pymongo.results import InsertOneResult, UpdateResult -from schedule import Job, Scheduler from components.database import subscriptions from components.subscriptions.typing import SubsDict from components.videos import VideoTuple -default_scheduler = Scheduler() - @dataclass class Subscription: _id: str @@ -26,15 +23,9 @@ class Subscription: def __post_init__(self) -> None: self._collection: Collection[SubsDict] = subscriptions - self._scheduler: Scheduler = default_scheduler if len(self.videos) and type(self.videos[0]) != VideoTuple: self.videos = [VideoTuple._make(vid) for vid in self.videos] - def initialise_job(self) -> None: - self._job: Job = self._scheduler.every(self.time_between_fetches).minutes.do(self.fetch) - if self.last_fetch > datetime.min.replace(tzinfo=UTC): - self._job.next_run += self.last_fetch - datetime.now(tz=UTC) - def fetch(self) -> None: try: rss = parse(self.link) diff --git a/components/subscriptions/typing.py b/components/subscriptions/typing.py index bac3620..c16d636 100644 --- a/components/subscriptions/typing.py +++ b/components/subscriptions/typing.py @@ -6,7 +6,7 @@ from components.videos import VideoTuple class SubsDict(TypedDict): _id: str link: str - time_between_fetches: int # In minutes. + time_between_fetches: int # In seconds. last_fetch: datetime last_video_update: datetime last_viewed: datetime -- cgit v1.2.3-70-g09d2