perf(automation): 持久队列驱动并优化履约热路径

This commit is contained in:
yml
2026-11-23 15:07:31 +08:00
parent 11c2a0dba7
commit 2549511598
31 changed files with 1658 additions and 235 deletions
+31
View File
@@ -17,13 +17,20 @@ python /app/services/yyb-worker/runtime/scripts/yyb-worker.py \
--data-dir /app/data/yyb-worker-jobs &
worker_pid=$!
web_pid=""
background_pid=""
stop_processes() {
kill -TERM "$worker_pid" 2>/dev/null || true
if [ -n "$background_pid" ]; then
kill -TERM "$background_pid" 2>/dev/null || true
fi
if [ -n "$web_pid" ]; then
kill -TERM "$web_pid" 2>/dev/null || true
fi
wait "$worker_pid" 2>/dev/null || true
if [ -n "$background_pid" ]; then
wait "$background_pid" 2>/dev/null || true
fi
if [ -n "$web_pid" ]; then
wait "$web_pid" 2>/dev/null || true
fi
@@ -31,6 +38,14 @@ stop_processes() {
trap stop_processes INT TERM
if [ "${BACKGROUND_RUNTIME_IN_SEPARATE_PROCESS:-true}" = "true" ]; then
RUNTIME_ROLE=background python -m web.backend.background_worker &
background_pid=$!
export RUNTIME_ROLE=api
else
export RUNTIME_ROLE=all
fi
python -m uvicorn web.backend.main:app --host 0.0.0.0 --port 8800 --workers 1 &
web_pid=$!
@@ -39,12 +54,28 @@ while :; do
if wait "$worker_pid"; then exit_code=0; else exit_code=$?; fi
kill -TERM "$web_pid" 2>/dev/null || true
wait "$web_pid" 2>/dev/null || true
if [ -n "$background_pid" ]; then
kill -TERM "$background_pid" 2>/dev/null || true
wait "$background_pid" 2>/dev/null || true
fi
exit "$exit_code"
fi
if ! kill -0 "$web_pid" 2>/dev/null; then
if wait "$web_pid"; then exit_code=0; else exit_code=$?; fi
kill -TERM "$worker_pid" 2>/dev/null || true
wait "$worker_pid" 2>/dev/null || true
if [ -n "$background_pid" ]; then
kill -TERM "$background_pid" 2>/dev/null || true
wait "$background_pid" 2>/dev/null || true
fi
exit "$exit_code"
fi
if [ -n "$background_pid" ] && ! kill -0 "$background_pid" 2>/dev/null; then
if wait "$background_pid"; then exit_code=0; else exit_code=$?; fi
kill -TERM "$web_pid" 2>/dev/null || true
wait "$web_pid" 2>/dev/null || true
kill -TERM "$worker_pid" 2>/dev/null || true
wait "$worker_pid" 2>/dev/null || true
exit "$exit_code"
fi
sleep 1