69 lines
2.5 KiB
PowerShell
69 lines
2.5 KiB
PowerShell
param(
|
|
[string]$TaskName = "NDC_ADDRESS_Nightly_Regression",
|
|
[string]$StartTime = "03:30",
|
|
[string]$PythonExe = "python",
|
|
[string]$BackendUrl = "http://127.0.0.1:8787/api/assistant/message",
|
|
[string]$LlmProvider = "local",
|
|
[string]$LlmModel = "qwen2.5-14b-instruct-1m",
|
|
[string]$LlmBaseUrl = "http://127.0.0.1:1234",
|
|
[ValidateSet("semantic", "route", "factual")]
|
|
[string]$StrictPolicy = "route",
|
|
[string]$OwnerUser = "",
|
|
[switch]$Unregister
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$RepoRoot = Split-Path -Parent $ScriptDir
|
|
$NightlyWrapper = Join-Path $ScriptDir "run_address_nightly_regression.ps1"
|
|
|
|
if (-not (Test-Path $NightlyWrapper)) {
|
|
throw "Nightly wrapper script not found: $NightlyWrapper"
|
|
}
|
|
|
|
if ($Unregister) {
|
|
if (Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue) {
|
|
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false
|
|
Write-Host "Removed scheduled task: $TaskName"
|
|
} else {
|
|
Write-Host "Scheduled task not found: $TaskName"
|
|
}
|
|
exit 0
|
|
}
|
|
|
|
if (-not $OwnerUser) {
|
|
if ($env:USERDOMAIN -and $env:USERNAME) {
|
|
$OwnerUser = "$($env:USERDOMAIN)\$($env:USERNAME)"
|
|
} else {
|
|
$OwnerUser = $env:USERNAME
|
|
}
|
|
}
|
|
|
|
$startDateTime = [DateTime]::ParseExact($StartTime, "HH:mm", $null)
|
|
$taskTrigger = New-ScheduledTaskTrigger -Daily -At $startDateTime
|
|
|
|
$taskArgs = @(
|
|
"-NoProfile",
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-File", "`"$NightlyWrapper`"",
|
|
"-PythonExe", "`"$PythonExe`"",
|
|
"-BackendUrl", "`"$BackendUrl`"",
|
|
"-LlmProvider", "`"$LlmProvider`"",
|
|
"-LlmModel", "`"$LlmModel`"",
|
|
"-LlmBaseUrl", "`"$LlmBaseUrl`"",
|
|
"-StrictPolicy", "`"$StrictPolicy`""
|
|
) -join " "
|
|
|
|
$taskAction = New-ScheduledTaskAction -Execute "powershell.exe" -Argument $taskArgs -WorkingDirectory $RepoRoot
|
|
$taskPrincipal = New-ScheduledTaskPrincipal -UserId $OwnerUser -LogonType Interactive -RunLevel Limited
|
|
$taskSettings = New-ScheduledTaskSettingsSet -StartWhenAvailable -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries
|
|
$taskObject = New-ScheduledTask -Action $taskAction -Trigger $taskTrigger -Principal $taskPrincipal -Settings $taskSettings
|
|
|
|
Register-ScheduledTask -TaskName $TaskName -InputObject $taskObject -Force | Out-Null
|
|
|
|
Write-Host "Scheduled task registered:"
|
|
Write-Host "- Name: $TaskName"
|
|
Write-Host "- Owner: $OwnerUser"
|
|
Write-Host "- StartTime: $StartTime (daily)"
|
|
Write-Host "- Action: powershell.exe $taskArgs"
|