Calculate and sleep checkpoint intervals for services

pull/50/head
Oleksandr Ieremeev 2018-08-19 19:06:59 +03:00
parent 3c2df53a7f
commit bbf29e946a
2 changed files with 8 additions and 1 deletions

View File

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

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