41 lines
2.3 KiB
PowerShell
41 lines
2.3 KiB
PowerShell
param()
|
|
$ErrorActionPreference = 'Stop'
|
|
$taskRoot = 'D:\web\zyt'
|
|
$phpBinary = 'D:\phpstudy_pro\Extensions\php\php8.2.9nts\php.exe'
|
|
$expected = @{ prepare = 33860; qwen = 7512; openai = 9292 }
|
|
$stamp = Get-Date -Format 'yyyyMMdd-HHmmss'
|
|
$receipt = @()
|
|
$diagnostic = Join-Path $taskRoot 'artifacts\prescription-ai-runtime\inspect_progress_environment.php'
|
|
|
|
function Assert-IdleQueue {
|
|
$raw = & $phpBinary $diagnostic
|
|
if ($LASTEXITCODE -ne 0) { throw 'Cannot verify queue state' }
|
|
$state = $raw | ConvertFrom-Json
|
|
if (-not $state.local_database -or -not $state.progress_column_present) { throw 'Local progress schema is not ready' }
|
|
if ($state.active_task_count -ne 0 -or $state.active_batch_count -ne 0 -or $state.active_preparation_count -ne 0) {
|
|
throw 'Queue is active; workers were not interrupted'
|
|
}
|
|
}
|
|
|
|
Assert-IdleQueue
|
|
$identities = @{}
|
|
foreach ($lane in @('prepare', 'qwen', 'openai')) {
|
|
$workers = @(Get-CimInstance Win32_Process -Filter "Name='php.exe'" | Where-Object { $_.CommandLine -match "prescription-ai:work --lane=$lane(?:\s|$)" })
|
|
if ($workers.Count -ne 1 -or $workers[0].ProcessId -ne $expected[$lane] -or $workers[0].ExecutablePath -ne $phpBinary) {
|
|
throw "Worker identity changed: $lane"
|
|
}
|
|
$identities[$lane] = $workers[0]
|
|
}
|
|
foreach ($lane in @('prepare', 'qwen', 'openai')) {
|
|
Assert-IdleQueue
|
|
$old = $identities[$lane]
|
|
Stop-Process -Id $old.ProcessId -ErrorAction Stop
|
|
Wait-Process -Id $old.ProcessId -Timeout 10 -ErrorAction SilentlyContinue
|
|
$outPath = Join-Path $taskRoot "artifacts\prescription-ai-runtime\$lane-progress-$stamp.stdout.log"
|
|
$errPath = Join-Path $taskRoot "artifacts\prescription-ai-runtime\$lane-progress-$stamp.stderr.log"
|
|
$started = Start-Process -FilePath $phpBinary -ArgumentList @('think', 'prescription-ai:work', "--lane=$lane") -WorkingDirectory (Join-Path $taskRoot 'server') -WindowStyle Hidden -RedirectStandardOutput $outPath -RedirectStandardError $errPath -PassThru
|
|
$receipt += [pscustomobject]@{lane=$lane; old_pid=$old.ProcessId; new_pid=$started.Id; started_at=(Get-Date).ToString('o'); stdout=$outPath; stderr=$errPath}
|
|
$receipt | ConvertTo-Json -Depth 3 | Set-Content -LiteralPath (Join-Path $taskRoot "artifacts\prescription-ai-runtime\progress-worker-reload-$stamp.json") -Encoding utf8
|
|
}
|
|
$receipt | ConvertTo-Json -Depth 3
|