abbe7a18fc
- P0: hooks.py 3-tuple fix, trigger_dispatcher Contract, contacts/plugin unregister_actions_by_owner - P0: 5 test files — check_permission mocks removed, hardcoded DB credential → env var - P1: attachment_service DmsFile via Contract helper, restore_registry/history_hooks dedup - P1: mail/plugin restore unregister, mcp_client datetime.now(UTC), saved_views/filters patterns - P1: ProtectedRoute fail-closed, 13 test assertion fixes (bcrypt, DB-URLs, SECRET_KEYs) - P2: deprecated notifications → post_system_message (3 files), forgejo Base, report_generator lazy import - P2: webhooks permissions, deps.py/roles.py plugin perms removed, import_export default - P2: address/tags/entity_links patterns removed, worker.py Contract-Umgehungen fixed - P2: 28 frontend TODOs (hardcoded constants, deprecated notification API) - P3: dead code, duplicates, deprecated imports, private attr, __import__ inline - P3: 8 frontend TODOs (LucideIcons, inline styles, XSS, i18n) - ruff: 838 → 0 (612 auto-fix + 246 manual + 27 F821 regression fix) - F821: 30 → 0 (AutomationDefinition, DmsFile, user_id, Path, Any, String) - Contract-Umgehungen: 2 neue gefunden (worker.py:169, worker.py:280) und gefixt
62 lines
1.6 KiB
Python
62 lines
1.6 KiB
Python
"""
|
|
Job Registry — decouples ARQ worker from direct plugin imports.
|
|
|
|
Plugins register their job functions via register_job() at import time.
|
|
The worker retrieves all registered jobs via get_all_jobs() instead of
|
|
importing from plugin modules directly.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from collections.abc import Callable, Coroutine
|
|
from typing import Any
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
# Type alias for an async job function
|
|
JobFunc = Callable[..., Coroutine[Any, Any, Any]]
|
|
|
|
# Internal registry: name -> job function
|
|
_registry: dict[str, JobFunc] = {}
|
|
|
|
|
|
def register_job(name: str, func: JobFunc) -> None:
|
|
"""Register a job function under the given name.
|
|
|
|
Args:
|
|
name: Unique job name (e.g. 'index_mails').
|
|
func: The async callable to register.
|
|
"""
|
|
if name in _registry:
|
|
logger.warning("Job '%s' is being re-registered — overwriting", name)
|
|
_registry[name] = func
|
|
logger.debug("Registered job: %s", name)
|
|
|
|
|
|
def get_job(name: str) -> JobFunc | None:
|
|
"""Retrieve a registered job function by name.
|
|
|
|
Args:
|
|
name: The job name to look up.
|
|
|
|
Returns:
|
|
The registered callable, or None if not found.
|
|
"""
|
|
return _registry.get(name)
|
|
|
|
|
|
def get_all_jobs() -> list[JobFunc]:
|
|
"""Return all registered job functions (order is insertion order).
|
|
|
|
Returns:
|
|
List of all registered async callables.
|
|
"""
|
|
return list(_registry.values())
|
|
|
|
|
|
def clear_registry() -> None:
|
|
"""Clear all registered jobs. Useful for testing."""
|
|
_registry.clear()
|
|
logger.debug("Job registry cleared")
|