-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.ps1
More file actions
156 lines (130 loc) · 4.4 KB
/
Copy pathdev.ps1
File metadata and controls
156 lines (130 loc) · 4.4 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
param(
[Parameter(Mandatory=$true)]
[ValidateSet("start", "stop", "restart", "reset", "logs", "rebuild", "status")]
[string]$cmd,
[int]$workers = 2
)
function Assert-Docker {
docker compose version | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "Docker Compose is required. Start Docker Desktop and try again."
}
}
function Wait-Postgres {
param([int]$TimeoutSeconds = 90)
Write-Host "Waiting for Postgres health..."
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
while ((Get-Date) -lt $deadline) {
$status = docker inspect -f "{{.State.Health.Status}}" mlis-postgres 2>$null
if ($LASTEXITCODE -eq 0 -and $status -eq "healthy") {
Write-Host "Postgres is healthy."
return
}
Start-Sleep -Seconds 2
}
throw "Timed out waiting for Postgres to become healthy."
}
function Wait-ApiReady {
param([int]$TimeoutSeconds = 90)
Write-Host "Waiting for API readiness..."
$deadline = (Get-Date).AddSeconds($TimeoutSeconds)
while ((Get-Date) -lt $deadline) {
try {
$response = Invoke-WebRequest -UseBasicParsing -Uri "http://localhost:8001/health/ready/full" -TimeoutSec 3
if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 300) {
Write-Host "API is ready."
return
}
} catch {
Start-Sleep -Seconds 2
continue
}
Start-Sleep -Seconds 2
}
throw "Timed out waiting for API readiness. Run .\dev.ps1 logs to inspect app/worker output."
}
function Write-StartupSummary {
Write-Host ""
Write-Host "Push scheduler demo stack is running."
Write-Host "Console: http://localhost:8001/console"
Write-Host "API readiness: http://localhost:8001/health/ready/full"
Write-Host "Scheduler mode: push"
Write-Host "Job source: db"
Write-Host "Database: Postgres"
Write-Host "Workers: $workers"
Write-Host ""
Write-Host "Use .\dev.ps1 logs to view logs, .\dev.ps1 stop to stop the stack."
}
function Start-App {
Assert-Docker
Write-Host "Building image..."
docker compose build
if ($LASTEXITCODE -ne 0) { throw "docker compose build failed." }
Write-Host "Starting Postgres..."
docker compose up -d postgres
if ($LASTEXITCODE -ne 0) { throw "Failed to start Postgres." }
Wait-Postgres
Write-Host "Starting API and worker containers in push mode..."
docker compose up -d --scale worker=$workers app worker
if ($LASTEXITCODE -ne 0) { throw "Failed to start app/worker containers." }
Wait-ApiReady
Write-StartupSummary
}
function Stop-App {
Assert-Docker
Write-Host "Stopping containers..."
docker compose down
}
function Restart-App {
Assert-Docker
Write-Host "Restarting app and worker containers..."
docker compose restart app worker
Wait-ApiReady
Write-StartupSummary
}
function Reset-App {
Assert-Docker
Write-Host "WARNING: This will delete database volume."
docker compose down -v
Write-Host "Rebuilding (no cache)..."
docker compose build --no-cache
if ($LASTEXITCODE -ne 0) { throw "docker compose build --no-cache failed." }
Write-Host "Starting fresh push-mode stack..."
docker compose up -d postgres
if ($LASTEXITCODE -ne 0) { throw "Failed to start Postgres." }
Wait-Postgres
docker compose up -d --scale worker=$workers app worker
if ($LASTEXITCODE -ne 0) { throw "Failed to start app/worker containers." }
Wait-ApiReady
Write-StartupSummary
}
function Rebuild-App {
Assert-Docker
Write-Host "Rebuilding image (no cache)..."
docker compose build --no-cache
if ($LASTEXITCODE -ne 0) { throw "docker compose build --no-cache failed." }
docker compose up -d postgres
if ($LASTEXITCODE -ne 0) { throw "Failed to start Postgres." }
Wait-Postgres
docker compose up -d --scale worker=$workers app worker
if ($LASTEXITCODE -ne 0) { throw "Failed to start app/worker containers." }
Wait-ApiReady
Write-StartupSummary
}
function Show-Logs {
Assert-Docker
docker compose logs -f postgres app worker
}
function Show-Status {
Assert-Docker
docker compose ps
}
switch ($cmd) {
"start" { Start-App }
"stop" { Stop-App }
"restart" { Restart-App }
"reset" { Reset-App }
"rebuild" { Rebuild-App }
"logs" { Show-Logs }
"status" { Show-Status }
}