Skip to content

Commit 218244c

Browse files
committed
Merge branch '425-health-check-attempts' into 'master'
fix(engine): increase health check attempts (#425) Closes #425 See merge request postgres-ai/database-lab!602
2 parents 633ba5b + 9f861b6 commit 218244c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

engine/internal/retrieval/engine/postgres/tools/health/healthcheck.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ const (
1717
hcInterval = 5 * time.Second
1818
hcTimeout = 2 * time.Second
1919
hcStartPeriod = 3 * time.Second
20-
hcRetries = 15
20+
21+
// HCRetries defines the default number of retries.
22+
HCRetries = 15
2123

2224
// DefaultRestoreInterval defines a default health check interval for database restoration.
2325
DefaultRestoreInterval = 5 * time.Second
@@ -36,7 +38,7 @@ func GetConfig(username, dbname string, options ...ContainerOption) *container.H
3638
Interval: hcInterval,
3739
Timeout: hcTimeout,
3840
StartPeriod: hcStartPeriod,
39-
Retries: hcRetries,
41+
Retries: HCRetries,
4042
}
4143

4244
for _, healthCheckOption := range options {

engine/internal/retrieval/engine/postgres/tools/tools.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/shirou/gopsutil/host"
3636

3737
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools/defaults"
38+
"gitlab.com/postgres-ai/database-lab/v3/internal/retrieval/engine/postgres/tools/health"
3839
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
3940
)
4041

@@ -321,7 +322,7 @@ func StopPostgres(ctx context.Context, dockerClient *client.Client, containerID,
321322
func CheckContainerReadiness(ctx context.Context, dockerClient *client.Client, containerID string) (err error) {
322323
log.Msg("Check container readiness: ", containerID)
323324

324-
var errorRepeats bool
325+
var errorRepeats int
325326

326327
for {
327328
select {
@@ -354,14 +355,14 @@ func CheckContainerReadiness(ctx context.Context, dockerClient *client.Client, c
354355
// Supposedly, the status 2 will be returned in cases where the server is not running
355356
// and will not start on its own, so there is no reason to wait for all specified retries.
356357
if lastHealthCheck := resp.State.Health.Log[healthCheckLength-1]; lastHealthCheck.ExitCode > 1 {
357-
if errorRepeats {
358+
if errorRepeats >= health.HCRetries {
358359
return &ErrHealthCheck{
359360
ExitCode: lastHealthCheck.ExitCode,
360361
Output: lastHealthCheck.Output,
361362
}
362363
}
363364

364-
errorRepeats = true
365+
errorRepeats++
365366
}
366367
}
367368
}

0 commit comments

Comments
 (0)