Files
inquiry_robot/inquiry-agent/agent/worker_app.py
T

55 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
智能体唯一 Worker 入口(LLM / 识别 / 报价 PDF / 存档)。
本文件职责:组装分槽运行时并阻塞至进程结束;不在此写各业务 Handler。
禁止:Redis wecom:worker:singleton;禁止五进程拆分;禁止在 HTTP 回调里跑本模块逻辑。
"""
from __future__ import annotations
import logging
import signal
import threading
from agent.config import get_settings
from agent.jobs import WorkerRuntime
logger = logging.getLogger(__name__)
def main() -> None:
"""
启动 Worker 槽与 inbox/outbox 占位线程,主线程等待停止信号。
副作用:创建后台线程;骨架不消费真实队列、不连库。
并发:LibreOffice 1 槽;HTTP 类至少 2~3 槽;与 inbox/outbox 隔离。
"""
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
)
settings = get_settings()
runtime = WorkerRuntime.from_settings(
libreoffice_slots=settings.libreoffice_slots,
http_job_slots=settings.http_job_slots,
)
runtime.start()
stop_event = threading.Event()
def _handle_signal(signum: int, _frame: object) -> None:
logger.info("收到停止信号 signum=%s", signum)
runtime.stop()
stop_event.set()
signal.signal(signal.SIGINT, _handle_signal)
signal.signal(signal.SIGTERM, _handle_signal)
logger.info("Worker 骨架运行中 ytd_env=%s(Ctrl+C 退出)", settings.ytd_env)
stop_event.wait()
logger.info("Worker 已退出")
if __name__ == "__main__":
main()