aboutsummaryrefslogtreecommitdiff
path: root/internal/monitor/scheduler.go
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-01-19 04:17:50 -0800
committerFuwn <[email protected]>2026-01-19 04:17:50 -0800
commit1e96ec397d38e6263c5369d91f2579092c9c9390 (patch)
treeb4b73accb870de9178acc931443c8cd474423fa5 /internal/monitor/scheduler.go
parentfeat: Add browser timezone option for client-side time display (diff)
downloadkaze-1e96ec397d38e6263c5369d91f2579092c9c9390.tar.xz
kaze-1e96ec397d38e6263c5369d91f2579092c9c9390.zip
feat: Add retry option for monitor checks
Diffstat (limited to 'internal/monitor/scheduler.go')
-rw-r--r--internal/monitor/scheduler.go31
1 files changed, 30 insertions, 1 deletions
diff --git a/internal/monitor/scheduler.go b/internal/monitor/scheduler.go
index 7a06131..5a7e817 100644
--- a/internal/monitor/scheduler.go
+++ b/internal/monitor/scheduler.go
@@ -100,7 +100,36 @@ func (s *Scheduler) executeCheck(mon Monitor) {
checkCtx, cancel := context.WithTimeout(s.ctx, mon.Interval())
defer cancel()
- result := mon.Check(checkCtx)
+ var result *Result
+ retries := mon.Retries()
+
+ // Try the check, with retries if configured
+ for attempt := 0; attempt <= retries; attempt++ {
+ result = mon.Check(checkCtx)
+
+ // If check succeeded (up or degraded), no need to retry
+ if result.Status == StatusUp || result.Status == StatusDegraded {
+ break
+ }
+
+ // If this wasn't the last attempt, log and retry
+ if attempt < retries {
+ s.logger.Debug("check failed, retrying",
+ "name", mon.Name(),
+ "attempt", attempt+1,
+ "max_retries", retries,
+ "error", result.Error)
+
+ // Small delay before retry (500ms)
+ select {
+ case <-checkCtx.Done():
+ // Context cancelled, abort retries
+ break
+ case <-time.After(500 * time.Millisecond):
+ // Continue to next retry
+ }
+ }
+ }
// Log the result
logAttrs := []any{