"""网关容器:集中管理网关侧服务实例,用于依赖注入""" from __future__ import annotations import asyncio import logging from dataclasses import dataclass from app.gateway.db import GatewayDB from app.gateway.task_queue import TaskQueue from app.shared.config import Settings logger = logging.getLogger(__name__) @dataclass(slots=True) class GatewayContainer: """网关容器 与抓取/交易容器同样的依赖注入风格,但持有的是任务队列与 SQLite 连接, 生命周期由 main.lifespan 管理:start 时打开 DB,close 时关闭。 `sweep_task` 是常驻后台扫描,把过期的 leased/running 推到 stale。 即使没有 lease 请求,过期的任务也会被及时发现(规格 §5 的关键约束)。 """ settings: Settings db: GatewayDB task_queue: TaskQueue sweep_task: asyncio.Task | None = None