Skip to content

Commit 62710ed

Browse files
committed
feat: 재시도 로직 작성
1 parent b2d75bf commit 62710ed

File tree

2 files changed

+60
-15
lines changed

2 files changed

+60
-15
lines changed

scripts/dev-setup.ps1

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,45 @@ if ($LASTEXITCODE -ne 0) {
1111
}
1212

1313
# 2. DB 초기화 대기
14-
Write-Host "2. Waiting for DB initialization (30 seconds)..." -ForegroundColor Yellow
15-
Start-Sleep -Seconds 30
14+
Write-Host "2. Waiting for DB and Redis to be ready..." -ForegroundColor Yellow
15+
16+
function Wait-ForUrl {
17+
param([string]$url, [int]$timeoutSec=120)
18+
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
19+
while ($stopwatch.Elapsed.TotalSeconds -lt $timeoutSec) {
20+
try {
21+
$resp = Invoke-WebRequest -Uri $url -TimeoutSec 3 -UseBasicParsing
22+
if ($resp.StatusCode -eq 200) { return $true }
23+
} catch { Start-Sleep -Milliseconds 500 }
24+
}
25+
return $false
26+
}
27+
28+
# Redis 연결 확인 (API를 통해)
29+
Write-Host "Checking Redis connectivity..." -ForegroundColor Cyan
30+
$redisReady = $false
31+
$maxWait = 60
32+
$elapsed = 0
33+
while (-not $redisReady -and $elapsed -lt $maxWait) {
34+
try {
35+
# Redis가 준비되었는지 간접적으로 확인 (포트 확인)
36+
$redisConnection = Test-NetConnection -ComputerName localhost -Port 6380 -WarningAction SilentlyContinue
37+
if ($redisConnection.TcpTestSucceeded) {
38+
Write-Host "Redis is ready!" -ForegroundColor Green
39+
$redisReady = $true
40+
} else {
41+
Start-Sleep -Seconds 2
42+
$elapsed += 2
43+
}
44+
} catch {
45+
Start-Sleep -Seconds 2
46+
$elapsed += 2
47+
}
48+
}
49+
50+
if (-not $redisReady) {
51+
Write-Host "Warning: Redis readiness check failed, continuing anyway..." -ForegroundColor Yellow
52+
}
1653

1754
# 3. API 빌드 및 시작
1855
Write-Host "3. Building and starting API..." -ForegroundColor Yellow

scripts/start-loadtest.ps1

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,21 @@ docker-compose -p projectvg-loadtest --env-file env.loadtest -f docker-compose.l
3535

3636
# Wait for services to start
3737
Write-Host "Waiting for services to start..." -ForegroundColor Yellow
38-
Start-Sleep -Seconds 3
3938

40-
# Check service status
41-
Write-Host "Checking service status..." -ForegroundColor Yellow
39+
function Wait-ForUrl {
40+
param([string]$url, [int]$timeoutSec=120)
41+
$stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
42+
while ($stopwatch.Elapsed.TotalSeconds -lt $timeoutSec) {
43+
try {
44+
$resp = Invoke-WebRequest -Uri $url -TimeoutSec 3 -UseBasicParsing
45+
if ($resp.StatusCode -eq 200) { return $true }
46+
} catch { Start-Sleep -Milliseconds 500 }
47+
}
48+
return $false
49+
}
50+
51+
# Check service status with retry
52+
Write-Host "Checking service status with retry..." -ForegroundColor Yellow
4253

4354
$services = @(
4455
@{Name="LLM Server"; Url="http://localhost:7808/health"},
@@ -49,16 +60,13 @@ $services = @(
4960

5061
$allHealthy = $true
5162
foreach ($service in $services) {
52-
try {
53-
$response = Invoke-RestMethod -Uri $service.Url -TimeoutSec 3
54-
if ($response.status -eq "ok" -or $response.Status -eq "Healthy") {
55-
Write-Host "$($service.Name): OK" -ForegroundColor Green
56-
} else {
57-
Write-Host "$($service.Name): FAILED" -ForegroundColor Red
58-
$allHealthy = $false
59-
}
60-
} catch {
61-
Write-Host "$($service.Name): CONNECTION FAILED" -ForegroundColor Red
63+
Write-Host "Waiting for $($service.Name)..." -ForegroundColor Cyan
64+
$isHealthy = Wait-ForUrl -url $service.Url -timeoutSec 120
65+
66+
if ($isHealthy) {
67+
Write-Host "$($service.Name): OK" -ForegroundColor Green
68+
} else {
69+
Write-Host "$($service.Name): TIMEOUT (120s)" -ForegroundColor Red
6270
$allHealthy = $false
6371
}
6472
}

0 commit comments

Comments
 (0)