refactor(backend): 后端重构初步设想

This commit is contained in:
sophie committed 2026-06-17 11:24:54 +08:00
1 parent b69d549b2c
commit 21b8c24815
96 files changed
+1592

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
"""
backend/app/jobs/registry.py
用途:JobType → Handler 注册表。
逻辑:handlers 模块 import 时 @register_handler 装饰;runner 按 type 分发。
"""
from __future__ import annotations
from collections.abc import Callable
from typing import Any
from app.jobs.types import JobType
HandlerFn = Callable[[Any, dict], None]
_REGISTRY: dict[JobType, HandlerFn] = {}
def register_handler(job_type: JobType) -> Callable[[HandlerFn], HandlerFn]:
"""
注册某 JobType 的处理函数。
Args:
job_type: 任务类型枚举。
Returns:
装饰器。
"""
def decorator(fn: HandlerFn) -> HandlerFn:
_REGISTRY[job_type] = fn
return fn
return decorator
def get_handler(job_type: JobType) -> HandlerFn | None:
"""按类型获取 handler;未注册返回 None。"""
return _REGISTRY.get(job_type)