mirror of https://github.com/statping/statping
Calculate and sleep checkpoint intervals for services
parent
3c2df53a7f
commit
bbf29e946a
|
@ -40,6 +40,8 @@ func CheckServices() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckQueue(s *Service, record bool) {
|
func CheckQueue(s *Service, record bool) {
|
||||||
|
s.Checkpoint = time.Now()
|
||||||
|
|
||||||
CheckLoop:
|
CheckLoop:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -49,7 +51,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