mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-13 00:00:01 -08:00
fix: inability to reload provider dynamically when using cached sessions
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
"""An abstraction over all providers offering added features with a simple and well typed api
|
||||
|
||||
[TODO:description]
|
||||
"""
|
||||
"""An abstraction over all providers offering added features with a simple and well typed api"""
|
||||
|
||||
import importlib
|
||||
import logging
|
||||
@@ -40,6 +37,10 @@ class AnimeProvider:
|
||||
|
||||
def lazyload_provider(self, provider):
|
||||
"""updates the current provider being used"""
|
||||
try:
|
||||
self.anime_provider.session.kill_connection_to_db()
|
||||
except Exception:
|
||||
pass
|
||||
_, anime_provider_cls_name = anime_sources[provider].split(".", 1)
|
||||
package = f"fastanime.libs.anime_provider.{provider}"
|
||||
provider_api = importlib.import_module(".api", package)
|
||||
|
||||
@@ -60,6 +60,7 @@ class CachedRequestsSession(requests.Session):
|
||||
):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self.lockfile_path = cache_db_lock_file
|
||||
self.cache_db_path = cache_db_path
|
||||
self.max_lifetime = max_lifetime
|
||||
self.max_size = max_size
|
||||
@@ -201,6 +202,11 @@ class CachedRequestsSession(requests.Session):
|
||||
content in caching_mimetypes[mime] for content in contents.split("+")
|
||||
)
|
||||
|
||||
def kill_connection_to_db(self):
|
||||
lockfile_path = pathlib.Path(self.lockfile_path)
|
||||
self.connection.close()
|
||||
lockfile_path.unlink(missing_ok=True)
|
||||
|
||||
@staticmethod
|
||||
def acquirer_lock(lock_file: str):
|
||||
"""the function creates a lock file preventing other instances of the cacher from running at the same time"""
|
||||
|
||||
Reference in New Issue
Block a user