Skip to content

Commit 58d8a48

Browse files
FIX (healthckeck): Add graceful shutdown for healthcheck
1 parent 8541ad7 commit 58d8a48

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

backend/internal/features/healthcheck/attempt/background_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package healthcheck_attempt
22

33
import (
44
"log/slog"
5+
"postgresus-backend/internal/config"
56
healthcheck_config "postgresus-backend/internal/features/healthcheck/config"
67
"time"
78
)
@@ -19,6 +20,10 @@ func (s *HealthcheckAttemptBackgroundService) RunBackgroundTasks() {
1920
ticker := time.NewTicker(time.Minute)
2021
defer ticker.Stop()
2122
for range ticker.C {
23+
if config.IsShouldShutdown() {
24+
break
25+
}
26+
2227
s.checkDatabases()
2328
}
2429
}

backend/internal/features/healthcheck/attempt/check_pg_health_uc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ func (uc *CheckPgHealthUseCase) sendDbStatusNotification(
225225
messageBody := ""
226226

227227
if newHealthStatus == databases.HealthStatusAvailable {
228-
messageTitle = fmt.Sprintf("✅ DB [%s] is back online", database.Name)
229-
messageBody = fmt.Sprintf("✅ The [%s] database is back online after being unavailable", database.Name)
228+
messageTitle = fmt.Sprintf("✅ [%s] DB is back online", database.Name)
229+
messageBody = fmt.Sprintf("✅ [%s] DB is back online after being unavailable", database.Name)
230230
} else {
231-
messageTitle = fmt.Sprintf("❌ DB [%s] is unavailable", database.Name)
232-
messageBody = fmt.Sprintf("❌ The [%s] database is currently unavailable", database.Name)
231+
messageTitle = fmt.Sprintf("❌ [%s] DB is unavailable", database.Name)
232+
messageBody = fmt.Sprintf("❌ [%s] DB is currently unavailable", database.Name)
233233
}
234234

235235
for _, notifier := range database.Notifiers {

backend/internal/features/healthcheck/attempt/check_pg_health_uc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ func Test_CheckPgHealthUseCase(t *testing.T) {
229229
t,
230230
"SendNotification",
231231
mock.Anything,
232-
fmt.Sprintf("❌ DB [%s] is unavailable", database.Name),
233-
fmt.Sprintf("❌ The [%s] database is currently unavailable", database.Name),
232+
fmt.Sprintf("❌ [%s] DB is unavailable", database.Name),
233+
fmt.Sprintf("❌ [%s] Database is currently unavailable", database.Name),
234234
)
235235
},
236236
)

0 commit comments

Comments
 (0)