mirror of https://github.com/statping/statping
Merge pull request #50 from oitimon/feature/calculate-sleep-interval
Calculate and sleep checkpoint intervals for servicespull/49/head^2
commit
5c70e61538
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue