fix(knowledge-base): 优化知识库页面,重构后端job队列

This commit is contained in:
sophie committed 2026-06-29 18:56:56 +08:00
1 parent 7e4a2037d8
commit b476b58a91
38 files changed
+992 -428

No files matched your search

+35
View File
@@ -0,0 +1,35 @@
"""
tests/jobs/test_worker_kb.py
用途:验证 KB worker 兼容入口读取 Flask config 中的并发配置。
"""
def test_main_kb_uses_app_config_concurrency(monkeypatch):
import worker_kb
started: list[str] = []
class FakeApp:
config = {'KB_WORKER_CONCURRENCY': 3}
class FakeProcess:
def __init__(self, *, target, args, name):
self.name = name
self.target = target
self.args = args
def start(self):
started.append(self.name)
def join(self, timeout=None):
return None
monkeypatch.setattr(worker_kb, 'create_app', lambda _config_name: FakeApp())
monkeypatch.setattr(worker_kb, '_resolve_config_name', lambda: 'production')
monkeypatch.setattr(worker_kb.mp, 'Process', FakeProcess)
worker_kb.main_kb()
# 断言多进程数量来自 app.config,而非直接读取环境变量默认值。
assert started == ['kb-worker-1', 'kb-worker-2', 'kb-worker-3']