aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/tasks/extension.py
diff options
context:
space:
mode:
Diffstat (limited to 'webmentions_ssg/tasks/extension.py')
-rw-r--r--webmentions_ssg/tasks/extension.py40
1 files changed, 18 insertions, 22 deletions
diff --git a/webmentions_ssg/tasks/extension.py b/webmentions_ssg/tasks/extension.py
index 9f53f3b..f7072b2 100644
--- a/webmentions_ssg/tasks/extension.py
+++ b/webmentions_ssg/tasks/extension.py
@@ -20,16 +20,14 @@ R = TypeVar("R")
class Huey:
- """
- Provide Flask integration for a Huey instance.
+ """Provide Flask integration for a Huey instance.
The extension initializes a Huey backend from the Flask configuration and
wraps tasks so that they execute within an application context.
"""
def __init__(self, app: Flask | None = None) -> None:
- """
- Initialize the Huey extension.
+ """Initialize the Huey extension.
:param app: Flask application to initialize immediately, if provided.
"""
@@ -40,8 +38,7 @@ class Huey:
self.init_app(app)
def init_app(self, app: Flask) -> None:
- """
- Initialize Huey for a Flask application.
+ """Initialize Huey for a Flask application.
The backend and its storage options are derived from ``HUEY_URL`` and the
resulting extension is registered with the application.
@@ -80,8 +77,7 @@ class Huey:
@property
def huey(self) -> BaseHuey:
- """
- Return the initialized Huey instance.
+ """Return the initialized Huey instance.
:return: Configured Huey backend instance.
:raises RuntimeError: If the extension has not been initialized.
@@ -128,8 +124,7 @@ class Huey:
return decorator
def __getattr__(self, name: str) -> Any:
- """
- Forward an unknown attribute to the underlying Huey instance.
+ """Forward an unknown attribute to the underlying Huey instance.
:param name: Name of the attribute to retrieve.
:return: Attribute from the initialized Huey instance.
@@ -139,8 +134,7 @@ class Huey:
@staticmethod
def backend_from_url(url: str) -> tuple[type[BaseHuey], dict[str, Any]]:
- """
- Determine the Huey backend and storage options from a URL.
+ """Determine the Huey backend and storage options from a URL.
:param url: Huey backend URL.
:return: Huey backend class and keyword arguments for its storage backend.
@@ -157,20 +151,22 @@ class Huey:
from huey import PriorityRedisExpireHuey
return PriorityRedisExpireHuey, {"url": fixed_url}
- elif scheme.endswith("priority"):
+
+ if scheme.endswith("priority"):
from huey import PriorityRedisHuey
return PriorityRedisHuey, {"url": fixed_url}
- elif scheme.endswith("expire"):
+
+ if scheme.endswith("expire"):
from huey import RedisExpireHuey
return RedisExpireHuey, {"url": fixed_url}
- else:
- from huey import RedisHuey
- return RedisHuey, {"url": url}
+ from huey import RedisHuey
+
+ return RedisHuey, {"url": url}
- elif scheme == "sqlite":
+ if scheme == "sqlite":
from huey import SqliteHuey
prefix = "sqlite:///"
@@ -187,7 +183,7 @@ class Huey:
return SqliteHuey, {"filename": filename}
- elif scheme == "file":
+ if scheme == "file":
from huey import FileHuey
prefix = "file:///"
@@ -204,17 +200,17 @@ class Huey:
return FileHuey, {"path": path}
- elif scheme in {"postgres", "postgresql"}:
+ if scheme in {"postgres", "postgresql"}:
from huey import PostgresHuey
return PostgresHuey, {"dsn": url}
- elif scheme == "memory":
+ if scheme == "memory":
from huey import MemoryHuey
return MemoryHuey, {}
- elif scheme == "blackhole":
+ if scheme == "blackhole":
from huey import BlackHoleHuey
return BlackHoleHuey, {}