refactor(scheduler): 排程迁移出web进程,迁入scheduler worker
This commit is contained in:
1 parent
970ee06537
commit
74745a9d10
21 files changed
+652
-223
No files matched your search
@@ -248,13 +248,13 @@ if [[ "${FRONTEND_CHANGED}" == "true" ]]; then
|
||||
services+=("hxops-frontend")
|
||||
fi
|
||||
if [[ "${BACKEND_CHANGED}" == "true" ]]; then
|
||||
# 知识库清洗与 backend 共用镜像;仅重建 backend 时 worker 会继续跑旧容器/旧代码
|
||||
services+=("hxops-backend" "hxops-kb-worker")
|
||||
# 后端与 worker 共用镜像;后端变更时同步更新,避免 worker 继续运行旧代码。
|
||||
services+=("hxops-backend" "hxops-kb-worker" "hxops-schedule-worker")
|
||||
fi
|
||||
|
||||
# 如果只是部署配置变更(如 compose/env/脚本),但前后端代码未改,则两边都更新
|
||||
if [[ ${#services[@]} -eq 0 && "${DEPLOY_CONFIG_CHANGED}" == "true" ]]; then
|
||||
services=("hxops-frontend" "hxops-backend" "hxops-kb-worker")
|
||||
services=("hxops-frontend" "hxops-backend" "hxops-kb-worker" "hxops-schedule-worker")
|
||||
fi
|
||||
|
||||
# 无变更则直接跳过,避免无意义重启
|
||||
|
||||
+15
-3
@@ -1,4 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# scripts/healthcheck.sh
|
||||
# 用途:部署后确认 Web 与后台 Worker 服务均处于 running。
|
||||
# 依赖:docker compose、docker-compose.yml、目标环境 env 文件。
|
||||
# 逻辑:逐个检查核心服务,避免仅按容器数量判断而漏掉 schedule/KB worker 启动失败。
|
||||
set -euo pipefail
|
||||
|
||||
ENV_NAME="${1:-default}"
|
||||
@@ -21,15 +26,22 @@ fi
|
||||
|
||||
max_attempts=20
|
||||
sleep_seconds=3
|
||||
required_services=(hxops-backend hxops-frontend hxops-kb-worker hxops-schedule-worker)
|
||||
|
||||
for ((i=1; i<=max_attempts; i++)); do
|
||||
status=$("${DC_CMD[@]}" "${compose_args[@]}" ps --status running --services | wc -l)
|
||||
if [[ "${status}" -ge 2 ]]; then
|
||||
mapfile -t running_services < <("${DC_CMD[@]}" "${compose_args[@]}" ps --status running --services)
|
||||
missing_services=()
|
||||
for service in "${required_services[@]}"; do
|
||||
if ! printf '%s\n' "${running_services[@]}" | grep -qx "${service}"; then
|
||||
missing_services+=("${service}")
|
||||
fi
|
||||
done
|
||||
if [[ ${#missing_services[@]} -eq 0 ]]; then
|
||||
echo "Healthcheck passed for ${ENV_NAME} environment."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Healthcheck waiting (${i}/${max_attempts})..."
|
||||
echo "Healthcheck waiting (${i}/${max_attempts}); missing: ${missing_services[*]}"
|
||||
sleep "${sleep_seconds}"
|
||||
done
|
||||
|
||||
|
||||
+18
-3
@@ -63,6 +63,7 @@ function Stop-StaleHxopsPythonProcesses {
|
||||
[regex]::Escape((Join-Path $BackendPath "run.py")),
|
||||
[regex]::Escape((Join-Path $BackendPath "worker_kb.py")),
|
||||
[regex]::Escape((Join-Path $BackendPath "workers\worker_shipping_notice.py")),
|
||||
[regex]::Escape((Join-Path $BackendPath "workers\worker_scheduler.py")),
|
||||
[regex]::Escape((Join-Path $RepoRoot "scripts\rpa\freight_rpa_worker.py"))
|
||||
)
|
||||
|
||||
@@ -334,6 +335,20 @@ function Start-ShippingWorkerWindow {
|
||||
-Command ".\venv\Scripts\python.exe .\workers\worker_shipping_notice.py"
|
||||
}
|
||||
|
||||
function Start-ScheduleWorkerWindow {
|
||||
param(
|
||||
[string]$BackendPath,
|
||||
[string]$Mode,
|
||||
[string]$DbUrl
|
||||
)
|
||||
|
||||
Start-WorkerWindow `
|
||||
-Title "schedule-worker" `
|
||||
-WorkingDirectory $BackendPath `
|
||||
-EnvPrefix (Get-DatabaseUrlExport -Mode $Mode -DbUrl $DbUrl) `
|
||||
-Command ".\venv\Scripts\python.exe .\workers\worker_scheduler.py"
|
||||
}
|
||||
|
||||
function Start-FreightRpaWorkerWindow {
|
||||
param(
|
||||
[string]$RepoRoot,
|
||||
@@ -386,7 +401,8 @@ Start-BackendWindow -BackendPath $backendDir -Mode $DbMode -DbUrl $DatabaseUrl
|
||||
if (-not $SkipWorker.IsPresent) {
|
||||
Start-KbWorkerWindow -BackendPath $backendDir -Mode $DbMode -DbUrl $DatabaseUrl
|
||||
Start-ShippingWorkerWindow -BackendPath $backendDir -Mode $DbMode -DbUrl $DatabaseUrl
|
||||
$windowCount += 2
|
||||
Start-ScheduleWorkerWindow -BackendPath $backendDir -Mode $DbMode -DbUrl $DatabaseUrl
|
||||
$windowCount += 3
|
||||
if (-not $SkipRpaWorker.IsPresent) {
|
||||
Start-FreightRpaWorkerWindow -RepoRoot $repoRoot -BackendPath $backendDir -EnvFiles $envFiles
|
||||
$windowCount += 1
|
||||
@@ -398,8 +414,7 @@ $windowCount += 1
|
||||
Write-Host ""
|
||||
Write-Host "Started in $windowCount new PowerShell windows." -ForegroundColor Green
|
||||
if (-not $SkipWorker.IsPresent) {
|
||||
Write-Host "Workers: kb-worker, shipping-worker$(if (-not $SkipRpaWorker.IsPresent) { ', freight-rpa-worker (mock)' })" -ForegroundColor Green
|
||||
Write-Host "Schedule worker runs inside backend process (SCHEDULE_WORKER_ENABLED)." -ForegroundColor DarkGray
|
||||
Write-Host "Workers: kb-worker, shipping-worker, schedule-worker$(if (-not $SkipRpaWorker.IsPresent) { ', freight-rpa-worker (mock)' })" -ForegroundColor Green
|
||||
}
|
||||
Write-Host "Frontend URL: http://127.0.0.1:8881" -ForegroundColor Green
|
||||
Write-Host "Backend URL: http://127.0.0.1:5052" -ForegroundColor Green
|
||||
|
||||
Reference in new issue
Block a user