Spaces:
Paused
Paused
| param( | |
| [string]$ProjectDir = (Split-Path -Parent (Split-Path -Parent $PSCommandPath)), | |
| [string]$PythonPath = (Get-Command python).Source, | |
| [string]$Time = "02:00", | |
| [string]$TaskName = "KPI-Dashboard-FactSync" | |
| ) | |
| $ScriptPath = Join-Path $ProjectDir "tools\run_sync.ps1" | |
| @" | |
| @`"$PythonPath`" -c `"import sys; sys.path.insert(0, '$ProjectDir'); from app import app; from services.platform_fetcher import fetch_all_facts; with app.app_context(): r = fetch_all_facts(); print(f'Saved: {r.get(`"`"values_saved`"`", 0)}'); [print(f'ERR: {e}') for e in r.get('errors', [])]`" | |
| "@ | Set-Content -Path $ScriptPath -Encoding UTF8 | |
| $Action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$ScriptPath`"" | |
| $Trigger = New-ScheduledTaskTrigger -Weekly -WeeksInterval 1 -DaysOfWeek Monday -At $Time | |
| $Principal = New-ScheduledTaskPrincipal -UserId "$env:USERDOMAIN\$env:USERNAME" -RunLevel Limited | |
| Register-ScheduledTask -TaskName $TaskName -Action $Action -Trigger $Trigger -Principal $Principal -Force | |
| Write-Output "Task '$TaskName' registered: every Monday at $Time" | |
| Write-Output "Script: $ScriptPath" | |
| Write-Output "" | |
| Write-Output "To run immediately: Start-ScheduledTask -TaskName '$TaskName'" | |
| Write-Output "To view: Get-ScheduledTask -TaskName '$TaskName'" | |
| Write-Output "To disable: Disable-ScheduledTask -TaskName '$TaskName'" | |