diff options
| author | Dennis Fink | 2026-11-12 19:57:08 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-12 19:57:08 +0100 |
| commit | 4bd1d9e348918b2e55db47a1ac3489d035cf55e2 (patch) | |
| tree | f7ed41a374a8a4136792039a262dc62aa8cf8c59 /webmentions_ssg/tasks/extension.py | |
| parent | 7035e9f9467684cccae2b7ff3faaa62e6a9f91aa (diff) | |
| download | webmentions-ssg-4bd1d9e348918b2e55db47a1ac3489d035cf55e2.tar.gz webmentions-ssg-4bd1d9e348918b2e55db47a1ac3489d035cf55e2.zip | |
refactor(core): split modules by responsibility
Break up monolithic views, task helpers, networking, CLI, and
application extension setup so each module owns a focused concern.
Reorganize the test suite around the new boundaries while preserving
existing Webmention behavior and coverage.
Diffstat (limited to 'webmentions_ssg/tasks/extension.py')
| -rw-r--r-- | webmentions_ssg/tasks/extension.py | 53 |
1 files changed, 18 insertions, 35 deletions
diff --git a/webmentions_ssg/tasks/extension.py b/webmentions_ssg/tasks/extension.py index df6cb21..9f53f3b 100644 --- a/webmentions_ssg/tasks/extension.py +++ b/webmentions_ssg/tasks/extension.py @@ -93,54 +93,37 @@ class Huey: ) return self._huey + def _in_app_context(self, func: Callable[P, R]) -> Callable[P, R]: + """Return a task wrapper that executes with the configured Flask app.""" + + @wraps(func) + def wrapped(*args: P.args, **kwargs: P.kwargs) -> R: + if self.app is None: + raise RuntimeError("Flask app is not available.") + with self.app.app_context(): + return func(*args, **kwargs) + + return wrapped + def task( self, *task_args: Any, **task_kwargs: Any ) -> Callable[[Callable[P, object]], TaskWrapper]: - """ - Create a Huey task that runs within the Flask application context. - - :param task_args: Positional arguments forwarded to Huey's task decorator. - :param task_kwargs: Keyword arguments forwarded to Huey's task decorator. - :return: Decorator that registers the wrapped function as a Huey task. - """ + """Return a Huey task decorator with Flask application context.""" def decorator(func: Callable[P, R]) -> TaskWrapper: - @wraps(func) - def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: - if self.app is None: - raise RuntimeError("Flask app is not available.") - - with self.app.app_context(): - return func(*args, **kwargs) - - return self.huey.task(*task_args, **task_kwargs)(wrapper) + return self.huey.task(*task_args, **task_kwargs)(self._in_app_context(func)) return decorator def periodic_task( self, *task_args: Any, **task_kwargs: Any ) -> Callable[[Callable[P, object]], TaskWrapper]: - """ - Create a periodic Huey task that runs within the Flask application context. - - :param task_args: Positional arguments forwarded to Huey's periodic task - decorator. - :param task_kwargs: Keyword arguments forwarded to Huey's periodic task - decorator. - :return: Decorator that registers the wrapped function as a periodic Huey - task. - """ + """Return a periodic Huey decorator with Flask application context.""" def decorator(func: Callable[P, R]) -> TaskWrapper: - @wraps(func) - def wrapper(*args: P.args, **kwargs: P.kwargs) -> R: - if self.app is None: - raise RuntimeError("Flask app is not available.") - - with self.app.app_context(): - return func(*args, **kwargs) - - return self.huey.periodic_task(*task_args, **task_kwargs)(wrapper) + return self.huey.periodic_task(*task_args, **task_kwargs)( + self._in_app_context(func) + ) return decorator |
