fix CI: move Python deps + reranker test to systemd ExecStartPre
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 8s
Some checks failed
Deploy API Server / build-and-deploy (push) Failing after 8s
Runner container lacks Python 3.11, so pip install and self-test now run as ExecStartPre in zhixi-worker.service on the host. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
9c8bd59620
commit
e0110fd8f8
@ -93,31 +93,16 @@ jobs:
|
||||
rsync -av --delete --exclude='.env' --exclude='__pycache__' \
|
||||
/tmp/api-server/rag-worker/ "$WORKER_DIR/"
|
||||
|
||||
# Install any new Python dependencies
|
||||
/usr/bin/python3.11 -m pip install -r "$WORKER_DIR/requirements.txt" \
|
||||
-i https://mirrors.tencentyun.com/pypi/simple 2>&1 | tail -3
|
||||
|
||||
# Reload systemd and restart worker
|
||||
# Copy service file and reload
|
||||
cp "$WORKER_DIR/zhixi-worker.service" /etc/systemd/system/
|
||||
systemctl daemon-reload
|
||||
systemctl restart zhixi-worker
|
||||
sleep 3
|
||||
systemctl is-active zhixi-worker && echo "[deploy] zhixi-worker restarted OK"
|
||||
|
||||
# Test reranker
|
||||
cd "$WORKER_DIR"
|
||||
/usr/bin/python3.11 -c "
|
||||
import asyncio
|
||||
from reranker import rerank
|
||||
async def t():
|
||||
r = await rerank('什么是主动回忆', [
|
||||
'主动回忆是一种高效的学习策略,通过主动从记忆中提取信息来强化神经连接',
|
||||
'苹果是一种常见的水果,富含维生素C',
|
||||
'间隔重复和主动回忆结合使用效果更佳',
|
||||
], top_n=2)
|
||||
for x in r:
|
||||
print(f'[rerank-test] score={x[\"score\"]:.4f} text={x[\"text\"][:40]}')
|
||||
asyncio.run(t())
|
||||
" && echo "[deploy] Reranker test OK"
|
||||
sleep 8
|
||||
systemctl is-active zhixi-worker && echo "[deploy] zhixi-worker active OK" || {
|
||||
echo "[deploy] zhixi-worker FAILED, checking logs:"
|
||||
journalctl -u zhixi-worker --no-pager -n 30
|
||||
exit 1
|
||||
}
|
||||
|
||||
- name: Health check
|
||||
run: |
|
||||
|
||||
30
rag-worker/zhixi-worker.service
Normal file
30
rag-worker/zhixi-worker.service
Normal file
@ -0,0 +1,30 @@
|
||||
[Unit]
|
||||
Description=ZhiXi RAG Worker
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=root
|
||||
WorkingDirectory=/opt/zhixi/backend/rag-worker
|
||||
Environment="PYTHONUNBUFFERED=1"
|
||||
EnvironmentFile=/opt/zhixi/backend/rag-worker/.env
|
||||
|
||||
# Install deps and self-test before starting main loop
|
||||
ExecStartPre=/usr/bin/python3.11 -m pip install -q -r /opt/zhixi/backend/rag-worker/requirements.txt -i https://mirrors.tencentyun.com/pypi/simple
|
||||
ExecStartPre=/usr/bin/python3.11 -c "
|
||||
import asyncio, sys
|
||||
from reranker import rerank
|
||||
async def t():
|
||||
r = await rerank('测试', ['这是测试文本', '无关内容'], top_n=1)
|
||||
if not r: raise RuntimeError('reranker returned empty')
|
||||
print(f'[self-test] reranker OK, score={r[0][\"score\"]:.4f}')
|
||||
asyncio.run(t())
|
||||
print('[self-test] all checks passed')
|
||||
"
|
||||
|
||||
ExecStart=/usr/bin/python3.11 -u main.py
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
x
Reference in New Issue
Block a user