Invoke-GlobalNavHotReloadSmoke.ps1
2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
param(
[string]$AppSettingsPath = "src/Rcs.Api/appsettings.Development.json",
[string]$ApiBaseUrl = "http://localhost:5000",
[int]$FirstHoldSecondsShort = 2,
[int]$SecondHoldSecondsShort = 5,
[int]$PauseSeconds = 8,
[switch]$RestoreAfter
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
if (-not (Test-Path $AppSettingsPath)) {
throw "Config file not found: $AppSettingsPath"
}
$raw = Get-Content -Path $AppSettingsPath -Raw
$json = $raw | ConvertFrom-Json
if (-not $json.AppSettings) {
throw "AppSettings section missing in $AppSettingsPath"
}
if (-not $json.AppSettings.GlobalNavigation) {
$json.AppSettings | Add-Member -NotePropertyName GlobalNavigation -NotePropertyValue ([pscustomobject]@{})
}
if (-not $json.AppSettings.GlobalNavigation.Coordinator) {
$json.AppSettings.GlobalNavigation | Add-Member -NotePropertyName Coordinator -NotePropertyValue ([pscustomobject]@{})
}
$backupPath = "$AppSettingsPath.bak.codex"
$raw | Set-Content -Path $backupPath -Encoding UTF8
function Set-HoldShort([int]$value) {
$json.AppSettings.GlobalNavigation.Coordinator.ResumeStablePassThreshold = $json.AppSettings.GlobalNavigation.Coordinator.ResumeStablePassThreshold ?? 2
$json.AppSettings.GlobalNavigation.Coordinator.HoldSecondsShort = $value
$json.AppSettings.GlobalNavigation.Coordinator.HoldSecondsQueue = $json.AppSettings.GlobalNavigation.Coordinator.HoldSecondsQueue ?? 3
$out = $json | ConvertTo-Json -Depth 100
$out | Set-Content -Path $AppSettingsPath -Encoding UTF8
Write-Host "[HotReload] Updated HoldSecondsShort=$value"
}
try {
Write-Host "[HotReload] Step 1: set HoldSecondsShort=$FirstHoldSecondsShort"
Set-HoldShort -value $FirstHoldSecondsShort
Start-Sleep -Seconds $PauseSeconds
Write-Host "[HotReload] Step 2: set HoldSecondsShort=$SecondHoldSecondsShort"
Set-HoldShort -value $SecondHoldSecondsShort
Start-Sleep -Seconds $PauseSeconds
Write-Host "[HotReload] Optional API probe: GET $ApiBaseUrl/api/FatigueTest/status"
try {
$probe = Invoke-RestMethod -Uri "$ApiBaseUrl/api/FatigueTest/status" -Method Get -TimeoutSec 10
Write-Host "[HotReload] Probe succeeded."
}
catch {
Write-Warning "[HotReload] Probe failed: $($_.Exception.Message)"
}
Write-Host "[HotReload] Check service logs for:"
Write-Host " [GlobalNav] ConfigUpdated ..."
Write-Host " [GlobalNav] DecisionMetrics ..."
}
finally {
if ($RestoreAfter.IsPresent -and (Test-Path $backupPath)) {
Copy-Item -Path $backupPath -Destination $AppSettingsPath -Force
Write-Host "[HotReload] Restored config from backup: $backupPath"
}
}