# Start prescription AI consumers. # -Mode Restart : stop every existing consumer first (use only when no task is running) # -Mode Add : leave running consumers alone and add missing instances # Concurrency needs one process per concurrent task: keep the per-lane counts at or above # prescription_analysis.max_parallel_per_model. param( [ValidateSet('Restart', 'Add')][string]$Mode = 'Add', [int]$Prepare = 2, [int]$Qwen = 4, [int]$OpenAi = 4 ) $ErrorActionPreference = 'Stop' $stamp = Get-Date -Format 'yyyyMMdd-HHmmss' $art = 'D:\web\zyt\artifacts\prescription-ai-runtime' $php = 'D:\phpstudy_pro\Extensions\php\php8.2.9nts\php.exe' $server = 'D:\web\zyt\server' $plan = @( @{ lane = 'prepare'; count = $Prepare }, @{ lane = 'qwen'; count = $Qwen }, @{ lane = 'openai'; count = $OpenAi } ) $records = @() foreach ($item in $plan) { $lane = $item.lane $existing = @(Get-CimInstance Win32_Process -Filter "Name='php.exe'" | Where-Object { $_.CommandLine -like "*prescription-ai:work*--lane=$lane*" }) if ($Mode -eq 'Restart') { foreach ($p in $existing) { Stop-Process -Id $p.ProcessId -Force } Start-Sleep -Milliseconds 400 $existing = @() } for ($i = $existing.Count + 1; $i -le $item.count; $i++) { $out = Join-Path $art "$lane-$i-$stamp.stdout.log" $err = Join-Path $art "$lane-$i-$stamp.stderr.log" $proc = Start-Process -FilePath $php -ArgumentList @('think', 'prescription-ai:work', "--lane=$lane") ` -WorkingDirectory $server -WindowStyle Hidden -RedirectStandardOutput $out -RedirectStandardError $err -PassThru $records += [pscustomobject]@{ lane = $lane; instance = $i; pid = $proc.Id; stdout = $out; stderr = $err } } } $path = Join-Path $art "worker-start-$stamp.json" $records | ConvertTo-Json -Depth 4 | Out-File -FilePath $path -Encoding utf8 Write-Output "mode=$Mode record=$path started=$($records.Count)" Get-CimInstance Win32_Process -Filter "Name='php.exe'" | Where-Object { $_.CommandLine -like '*prescription-ai:work*' } | ForEach-Object { Write-Output ("{0} {1}" -f $_.ProcessId, ($_.CommandLine -replace '.*--lane=', 'lane=')) }