#!/bin/bash set -u PROJECT_ROOT="/home/gao/Development/quant_home/market_sync" LOG_DIR="$PROJECT_ROOT/logs" RUN_LOG="$LOG_DIR/run_all_sync_$(date +%Y%m%d_%H%M%S).log" cd "$PROJECT_ROOT" LOG_PREFIX="[run_all_sync]" run_step() { local step=$1 task=$2 extra_args=${3:-} echo "$LOG_PREFIX === 步骤 $step: $task ===" | tee -a "$RUN_LOG" if [ -n "$extra_args" ]; then .venv/bin/python -m app.entrypoints.cli sync "$task" $extra_args 2>&1 | tee -a "$RUN_LOG" else .venv/bin/python -m app.entrypoints.cli sync "$task" 2>&1 | tee -a "$RUN_LOG" fi local rc=${PIPESTATUS[0]} if [ $rc -ne 0 ]; then echo "$LOG_PREFIX ✗ 步骤 $step ($task) 失败 (exit=$rc)" | tee -a "$RUN_LOG" return $rc fi echo "$LOG_PREFIX ✓ 步骤 $step ($task) 完成" | tee -a "$RUN_LOG" } case "${1:-all}" in 1|stock_basic) run_step "1_stock_basic" "stock_basic" ;; 2|kline_index) run_step "2_kline_index" "kline_index" ;; 3|kline_daily) run_step "3_kline_daily" "kline_daily" "--workers 20" ;; 4|share_snapshot) run_step "4_share_snapshot" "share_snapshot" "--workers 10" ;; 5|market_regime) run_step "5_market_regime" "market_regime" ;; 6|kline_5min) run_step "6_kline_5min" "kline_5min" "--workers 10" ;; 7|moneyflow) run_step "7_moneyflow" "moneyflow" "--workers 10" ;; 8|tick_trade) run_step "8_tick_trade" "tick_trade" "--workers 5 --force" ;; all) run_step "1_stock_basic" "stock_basic" || exit 1 run_step "2_kline_index" "kline_index" || exit 1 run_step "3_kline_daily" "kline_daily" "--workers 20" || exit 1 run_step "4_share_snapshot" "share_snapshot" "--workers 10" || exit 1 run_step "5_market_regime" "market_regime" || exit 1 run_step "6_kline_5min" "kline_5min" "--workers 10" || exit 1 run_step "7_moneyflow" "moneyflow" "--workers 10" || exit 1 run_step "8_tick_trade" "tick_trade" "--workers 5 --force" || exit 1 echo "$LOG_PREFIX ✓ 全部 8 步完成" | tee -a "$RUN_LOG" ;; *) echo "usage: $0 [1|2|3|4|5|6|7|8|all]" exit 1 ;; esac