diff options
| author | Fuwn <[email protected]> | 2026-01-19 04:17:50 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-01-19 04:17:50 -0800 |
| commit | 1e96ec397d38e6263c5369d91f2579092c9c9390 (patch) | |
| tree | b4b73accb870de9178acc931443c8cd474423fa5 /internal/monitor/scheduler.go | |
| parent | feat: Add browser timezone option for client-side time display (diff) | |
| download | kaze-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.go | 31 |
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{ |