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) {
|
func (s *Service) CheckQueue(record bool) {
|
||||||
|
s.Checkpoint = time.Now()
|
||||||
|
|
||||||
CheckLoop:
|
CheckLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -50,7 +52,11 @@ CheckLoop:
|
||||||
default:
|
default:
|
||||||
utils.Log(1, fmt.Sprintf("Checking service: %v", s.Name))
|
utils.Log(1, fmt.Sprintf("Checking service: %v", s.Name))
|
||||||
ServiceCheck(s, record)
|
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
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ type Service struct {
|
||||||
Failures []*Failure `json:"failures"`
|
Failures []*Failure `json:"failures"`
|
||||||
Checkins []*Checkin `json:"checkins"`
|
Checkins []*Checkin `json:"checkins"`
|
||||||
Running chan bool `json:"-"`
|
Running chan bool `json:"-"`
|
||||||
|
Checkpoint time.Time `json:"-"`
|
||||||
LastResponse string
|
LastResponse string
|
||||||
LastStatusCode int
|
LastStatusCode int
|
||||||
LastOnline time.Time
|
LastOnline time.Time
|
||||||
|
|
Loading…
Reference in New Issue