o2o-negosium-original/lps/run_local_worker.sh
민헌 0e30354ba5 feat(lps): 로컬 워커·부하테스트(GUI) 실행 스크립트 추가 (대화형)
기존 run_local_server.sh 스타일에 맞춘 대화형 .sh 두 개.

- run_local_worker.sh: 동시성(WORKER_CONCURRENCY)·Chrome 프로필(LPS_PROFILE_DIR)
  선택 후 워커 기동. 실행 중 워커 감지 시 교체 여부 확인. venv/config 자동 보장.
- run_loadtest_gui.sh: Locust 웹 UI(:8089) 기동. 워커 실행 중이면 경고(크롤 비용),
  API 미기동 시 PROCESS_COUNT 받아 백그라운드 기동(종료 시 함께 정리). 부하생성기 --processes.
- .gitignore(lps): .profiles/(Chrome 쿠키·cf_clearance 세션) 커밋 방지
- README·operations: 새 스크립트 안내로 갱신

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 08:33:11 +09:00

60 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
#
# 로컬 LPS 워커 실행 (대화형). 실행하면 동시성 등을 골라 입력한다.
# 최초 실행 시 venv 생성 + 의존성 설치까지 자동으로 한다.
# 워커 = 실제 검색 수행(네이버/쿠팡/오픈마켓 크롤). 실행 시 쿠팡용 Chrome 창이 뜬다(정상).
#
set -euo pipefail
cd "$(dirname "$0")" # lps/
VENV=".venv"
PY="$VENV/bin/python"
# 1) venv + 의존성 보장
if [[ ! -d "$VENV" ]]; then
echo "[setup] venv 생성 + 의존성 설치..."
python3 -m venv "$VENV"
"$PY" -m pip install -q --upgrade pip
"$PY" -m pip install -q -r requirements.txt
fi
# 2) config 보장
if [[ ! -f config/config.local.toml ]]; then
echo "[error] config/config.local.toml 이 없습니다. 아래로 생성 후 값을 채우세요:"
echo " cp config/config.local.toml.example config/config.local.toml"
exit 1
fi
# 3) 이미 워커가 떠 있으면 안내
if pgrep -f worker_main.py >/dev/null 2>&1; then
echo "[info] 이미 워커(worker_main.py)가 실행 중입니다."
read -rp "기존 워커를 종료하고 새로 띄울까요? [y/N]: " kill_old
if [[ "${kill_old:-N}" =~ ^[Yy] ]]; then
pkill -f worker_main.py || true; sleep 1; echo "[info] 기존 워커 종료"
else
echo "취소합니다."; exit 0
fi
fi
# 4) 동시성 입력 (상품 동시 검색 수 · 워커별 브라우저 세트 · Chrome 최대 4×N개)
echo "── 워커 설정 ──"
read -rp "동시 검색 수 WORKER_CONCURRENCY [3] (로컬 권장 2~3): " CONC
CONC="${CONC:-3}"
# 5) Chrome 프로필 영속 디렉터리 (재시작해도 cf_clearance 유지 → 재웜업 회피). 비우면 기본(/tmp)
read -rp "Chrome 프로필 디렉터리 LPS_PROFILE_DIR [.profiles] (엔터=유지): " PROFILE
PROFILE="${PROFILE:-.profiles}"
mkdir -p "$PROFILE"
export APP_ENV=local
export WORKER_CONCURRENCY="$CONC"
export LPS_PROFILE_DIR="$PROFILE"
export PYTHONUNBUFFERED=1 # 로그 실시간 출력
echo ""
echo "[run] worker_main.py (동시성=$CONC · 프로필=$PROFILE)"
echo " 기동 로그의 'DECODO 프리플라이트 OK — egress IP ...' / 'AI: ON/OFF' 확인"
echo " 중단: Ctrl+C"
echo ""
exec "$PY" worker_main.py