thread-master/infra/start-node-worker.sh

47 lines
1.3 KiB
Bash
Raw Normal View History

2026-06-30 07:09:44 +00:00
#!/usr/bin/env bash
# 人設 8D Node workerPlaywright 公開爬蟲)
# 設定一律讀 infra/.env
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ENV_FILE="$ROOT/infra/.env"
WORKER_DIR="$ROOT/backend/worker"
if [[ ! -f "$ENV_FILE" ]]; then
echo "找不到 $ENV_FILE請先cp infra/.env.example infra/.env" >&2
exit 1
fi
set -a
# shellcheck disable=SC1090
source "$ENV_FILE"
set +a
: "${HAIXUN_BACKEND_URL:=http://127.0.0.1:8890}"
: "${HAIXUN_WORKER_SECRET:?請在 infra/.env 設定 HAIXUN_WORKER_SECRET}"
: "${HAIXUN_NODE_WORKER_ID:=local-style-8d}"
: "${HAIXUN_WORKER_POLL_MS:=3000}"
: "${HAIXUN_8D_TARGET_SAMPLES:=4}"
: "${PLAYWRIGHT_HEADLESS:=true}"
export HAIXUN_BACKEND_URL HAIXUN_WORKER_SECRET HAIXUN_NODE_WORKER_ID
export HAIXUN_WORKER_POLL_MS HAIXUN_8D_TARGET_SAMPLES PLAYWRIGHT_HEADLESS
echo "[start-node-worker] backend=$HAIXUN_BACKEND_URL worker_id=$HAIXUN_NODE_WORKER_ID"
if ! curl -sf "${HAIXUN_BACKEND_URL}/api/v1/health" >/dev/null; then
echo "[start-node-worker] API 連不上,請先啟動 gateway並 source infra/.env" >&2
exit 1
fi
cd "$WORKER_DIR"
if [[ ! -d node_modules ]]; then
echo "[start-node-worker] npm install…"
npm install
fi
echo "[start-node-worker] 確認 Playwright Chromium已安裝會略過…"
npx playwright install chromium
exec npm run style-8d