diff options
| author | A Farzat <a@farzat.xyz> | 2025-10-05 07:24:22 +0300 |
|---|---|---|
| committer | A Farzat <a@farzat.xyz> | 2025-10-05 07:24:22 +0300 |
| commit | 3b418daf684f01a126a56b58c83120af5914f576 (patch) | |
| tree | 20b6ea9487cce5a90cff8696085b8c3f7783db75 /components | |
| parent | 66194a36af3d1f6897e8fd0e3b61388cb18f6e1f (diff) | |
| download | csca5028-3b418daf684f01a126a56b58c83120af5914f576.tar.gz csca5028-3b418daf684f01a126a56b58c83120af5914f576.zip | |
Remove the redundant scheduler class
This allows fetching the database every time, ensuring any updates to
the database between fetches as captured.
Diffstat (limited to 'components')
| -rw-r--r-- | components/subscriptions/main.py | 9 | ||||
| -rw-r--r-- | components/subscriptions/typing.py | 2 |
2 files changed, 1 insertions, 10 deletions
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 |
