Merge pull request #50 from oitimon/feature/calculate-sleep-interval

Calculate and sleep checkpoint intervals for services
pull/49/head^2
Hunter Long 2018-08-20 01:25:39 -07:00 committed by GitHub
commit 5c70e61538
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -41,6 +41,8 @@ func CheckServices() {
}
func (s *Service) CheckQueue(record bool) {
s.Checkpoint = time.Now()
CheckLoop:
for {
select {
@ -50,7 +52,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
}
}

View File

@ -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