Skip to content

Commit ba764af

Browse files
committed
bouncer-fixes
1 parent 904092a commit ba764af

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

internal/api/handlers/health_diagnostics.go

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,7 @@ func parseBouncersJSON(bouncerOutput string, computeStatus bool) ([]models.Bounc
6161
bouncer.Valid = true
6262

6363
if computeStatus {
64-
// Determine last activity: prefer last_pull, fall back to updated_at
65-
// if the bouncer has been active since registration (updated_at > created_at + 5s).
66-
lastActivity := bouncer.LastPull
67-
if lastActivity.IsZero() &&
68-
bouncer.UpdatedAt.After(bouncer.CreatedAt.Add(5*time.Second)) {
69-
lastActivity = bouncer.UpdatedAt
70-
}
64+
lastActivity := bouncer.LastActivity()
7165

7266
if !lastActivity.IsZero() && time.Since(lastActivity) <= 5*time.Minute {
7367
bouncer.Status = "connected"
@@ -118,11 +112,7 @@ func checkBouncersHealth(dockerClient *docker.Client, containerName string) mode
118112

119113
activeBouncers := 0
120114
for _, b := range bouncers {
121-
lastActivity := b.LastPull
122-
if lastActivity.IsZero() &&
123-
b.UpdatedAt.After(b.CreatedAt.Add(5*time.Second)) {
124-
lastActivity = b.UpdatedAt
125-
}
115+
lastActivity := b.LastActivity()
126116
if !lastActivity.IsZero() && time.Since(lastActivity) <= 60*time.Minute {
127117
activeBouncers++
128118
}

internal/models/models.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,20 @@ type Bouncer struct {
158158
Status string `json:"status"`
159159
}
160160

161+
// LastActivity returns the best-known last activity time for this bouncer.
162+
// It prefers LastPull; falls back to UpdatedAt only when LastPull is zero
163+
// and UpdatedAt meaningfully exceeds CreatedAt (both must be non-zero).
164+
func (b Bouncer) LastActivity() time.Time {
165+
if !b.LastPull.IsZero() {
166+
return b.LastPull
167+
}
168+
if !b.CreatedAt.IsZero() && !b.UpdatedAt.IsZero() &&
169+
b.UpdatedAt.After(b.CreatedAt.Add(5*time.Second)) {
170+
return b.UpdatedAt
171+
}
172+
return time.Time{}
173+
}
174+
161175
// IPInfo represents IP address information
162176
type IPInfo struct {
163177
IP string `json:"ip"`

0 commit comments

Comments
 (0)