"""单独补跑 DWS_ASSISTANT_SALARY（设置 allow_out_of_cycle=True 绕过月初限制）

背景：联调时 ETL 运行日期为 2/27，day=27 > run_days=5，_should_skip_run 返回 True，
导致 4 个窗口切片全部跳过（ins=0）。本脚本设置环境变量后通过 CLI 补跑。
"""
import os, subprocess, sys
from pathlib import Path
from dotenv import load_dotenv

load_dotenv(Path(__file__).resolve().parents[2] / ".env")

# 设置 allow_out_of_cycle 环境变量
os.environ["DWS_SALARY_ALLOW_OUT_OF_CYCLE"] = "1"

# 通过 CLI 运行
cmd = [
    sys.executable, "-m", "cli.main",
    "--tasks", "DWS_ASSISTANT_SALARY",
    "--flow", "dwd_dws",
    "--processing-mode", "full_window",
    "--window-start", "2025-11-01",
    "--window-end", "2026-02-27",
    "--window-split", "day",
    "--window-split-days", "30",
    "--force-full",
]

cwd = Path(__file__).resolve().parents[2] / "apps" / "etl" / "connectors" / "feiqiu"

print(f"工作目录: {cwd}")
print(f"命令: {' '.join(cmd)}")
print(f"DWS_SALARY_ALLOW_OUT_OF_CYCLE={os.environ.get('DWS_SALARY_ALLOW_OUT_OF_CYCLE')}")
print("=" * 60)

result = subprocess.run(cmd, cwd=str(cwd), capture_output=False)
sys.exit(result.returncode)
