Files
sanguo_vnpy_v2/scripts/data_platform/register_akshare_schtasks.ps1
T

89 lines
5.0 KiB
PowerShell

# register_akshare_schtasks.ps1 — 注册 akshare 静态数据 schtask (与 VPS 现场命名一致)
#
# ⚠️ 命名史 (2026-09-01 事故教训):
# 2026-08-20 schtask 重组把任务改名为 ak-daily/ak-monthly/ak-weekly (wrapper 不变),
# 但本脚本当时没跟上, 仍是旧名 ak-eod/ak-quarter/ak-stock——09-01 晚重跑旧脚本:
# ① 复活了与 ak-weekly 完全重复的 ak-stock (同 wrapper 同时刻, 会双开并发)
# ② ak-quarter 行 /d SAT 在 zh-CN schtasks 上报「/D 选项无效」(/m 月份列表+英文星期
# 组合不被接受), 月度任务根本没注册上
# 修复: ak-stock 已删、ak-monthly 已改 XML 首周六; 本脚本重写为现场命名+XML 方式。
#
# 任务地图 (跑完核对):
# sanguo-ak-daily daily 19:00 ak_eod_wrapper.ps1 (valuation+financial_abstract)
# sanguo-ak-events daily 19:30 ak_events_wrapper.ps1
# sanguo-ak-weekly weekly SAT 03:00 ak_stock_wrapper.ps1
# sanguo-ak-monthly 财报月(APR,MAY,SEP,NOV)首个周六 02:00 ak_quarter_wrapper.ps1 ← XML 方式
# sanguo-ak-vintage daily 09:00 ak_vintage_wrapper.ps1 (vintage 一致性自检, 2026-09-01 新增)
# sanguo-index monthly 16 19:50 index_monthly_wrapper.ps1
#
# ak-monthly 为何 XML: ①zh-CN schtasks 不吃 "/m APR,MAY,SEP,NOV /d SAT" (09-01 实测
# 报「/D 选项无效」) ②洗库单趟 20h+, 月内1号02:00 只有 7.5h 夜窗必穿交易日 (09-01
# 首爆 16h+ 穿全天, 09:32 决策窗撞两表 vintage 撕裂致 value 清仓), 首个周六有 55h 跑道。
#
# 坑(2026-07-24 实证): PowerShell 调 schtasks 时双引号内反斜杠路径被吃 → 用 --% 或全路径;
# 查 Arguments 用 `schtasks /query /tn X /xml` (Get-ScheduledTask 在中文 Win 报 0x80070057)。
$env:http_proxy = ''
$env:https_proxy = ''
$env:all_proxy = ''
schtasks --% /create /tn sanguo-ak-daily /tr "powershell -ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\ak_eod_wrapper.ps1" /sc daily /st 19:00 /ru SYSTEM /rl HIGHEST /f
schtasks --% /create /tn sanguo-ak-events /tr "powershell -ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\ak_events_wrapper.ps1" /sc daily /st 19:30 /ru SYSTEM /rl HIGHEST /f
schtasks --% /create /tn sanguo-ak-weekly /tr "powershell -ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\ak_stock_wrapper.ps1" /sc weekly /d SAT /st 03:00 /ru SYSTEM /rl HIGHEST /f
schtasks --% /create /tn sanguo-ak-vintage /tr "powershell -ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\ak_vintage_wrapper.ps1" /sc daily /st 09:00 /ru SYSTEM /rl HIGHEST /f
schtasks --% /create /tn sanguo-index /tr "powershell -ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\index_monthly_wrapper.ps1" /sc monthly /d 16 /st 19:50 /ru SYSTEM /rl HIGHEST /f
# sanguo-ak-monthly: 财报月首个周六 02:00 (XML: zh-CN schtasks 不支持 /d 星期名+/m 月份列表)
$monthlyXml = @'
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Description>财报季月(APR/MAY/SEP/NOV)首个周六 02:00 akshare 三表+预告/快报 --force 全量洗库(单趟20h+只能周末跑)</Description>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<StartBoundary>2026-07-24T02:00:00</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByMonthDayOfWeek>
<Weeks>
<Week>1</Week>
</Weeks>
<DaysOfWeek>
<Saturday />
</DaysOfWeek>
<Months>
<April /><May /><September /><November />
</Months>
</ScheduleByMonthDayOfWeek>
</CalendarTrigger>
</Triggers>
<Settings>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
</Settings>
<Actions Context="Author">
<Exec>
<Command>powershell</Command>
<Arguments>-ExecutionPolicy Bypass -File C:\sanguo_vnpy_v2\scripts\data_platform\ak_quarter_wrapper.ps1</Arguments>
</Exec>
</Actions>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
</Task>
'@
$xmlPath = Join-Path $env:TEMP 'sanguo_ak_monthly_task.xml'
$monthlyXml | Out-File -FilePath $xmlPath -Encoding Unicode
schtasks /create /tn sanguo-ak-monthly /xml "$xmlPath" /f
Remove-Item $xmlPath -ErrorAction SilentlyContinue
Write-Output "=== VERIFY 下次运行时间 (应: daily=明19:00 / events=明19:30 / weekly=周六03:00 / monthly=财报月首个周六02:00 / vintage=明09:00 / index=16号19:50) ==="
foreach ($t in @('sanguo-ak-daily','sanguo-ak-events','sanguo-ak-weekly','sanguo-ak-monthly','sanguo-ak-vintage','sanguo-index')) {
schtasks /query /tn $t /fo LIST /v | Select-String -Pattern '下次运行时间|Next Run Time' | ForEach-Object { Write-Output (" {0,-18} {1}" -f $t, $_.Line.Trim()) }
}