diff --git a/core/checker.go b/core/checker.go index 45a62da2..ca349b3e 100644 --- a/core/checker.go +++ b/core/checker.go @@ -40,6 +40,8 @@ func CheckServices() { } func CheckQueue(s *Service, record bool) { + s.Checkpoint = time.Now() + CheckLoop: for { select { @@ -49,7 +51,11 @@ CheckLoop: default: utils.Log(1, fmt.Sprintf("Checking service: %v", s.Name)) ServiceCheck(s, record) - time.Sleep(time.Duration(s.Interval) * time.Second) + // Set next time checkpoint and maybe sleep. + s.Checkpoint = s.Checkpoint.Add(time.Duration(s.Interval) * time.Second) + if sleepDuration := s.Checkpoint.Sub(time.Now()); sleepDuration > 0 { + time.Sleep(sleepDuration) + } continue } } diff --git a/types/service.go b/types/service.go index e49eca19..45afcdbc 100644 --- a/types/service.go +++ b/types/service.go @@ -41,6 +41,7 @@ type Service struct { Failures []*Failure `json:"failures"` Checkins []*Checkin `json:"checkins"` Running chan bool `json:"-"` + Checkpoint time.Time `json:"-"` LastResponse string LastStatusCode int LastOnline time.Time