mirror of https://github.com/statping/statping
vue
parent
51a03bd574
commit
7f862ff2b9
|
@ -39,8 +39,8 @@ func (c *Checkin) Select() *types.Checkin {
|
|||
|
||||
// Routine for checking if the last Checkin was within its interval
|
||||
func CheckinRoutine(checkin database.Checkiner) {
|
||||
c := checkin.Object()
|
||||
if c.Hits().Last() == nil {
|
||||
c := checkin.Model()
|
||||
if checkin.Hits().Last() == nil {
|
||||
return
|
||||
}
|
||||
reCheck := c.Period()
|
||||
|
@ -53,11 +53,11 @@ CheckinLoop:
|
|||
break CheckinLoop
|
||||
case <-time.After(reCheck):
|
||||
log.Infoln(fmt.Sprintf("Checkin %v is expected at %v, checking every %v", c.Name, utils.FormatDuration(c.Expected()), utils.FormatDuration(c.Period())))
|
||||
if c.Expected().Seconds() <= 0 {
|
||||
issue := fmt.Sprintf("Checkin %v is failing, no request since %v", c.Name, c.Hits().Last().CreatedAt)
|
||||
if c.Expected() <= 0 {
|
||||
issue := fmt.Sprintf("Checkin %v is failing, no request since %v", c.Name, checkin.Hits().Last().CreatedAt)
|
||||
log.Errorln(issue)
|
||||
|
||||
CreateCheckinFailure(c)
|
||||
CreateCheckinFailure(checkin)
|
||||
}
|
||||
reCheck = c.Period()
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ func (c *Checkin) String() string {
|
|||
}
|
||||
|
||||
func CreateCheckinFailure(checkin database.Checkiner) (int64, error) {
|
||||
c := checkin.Object()
|
||||
service := c.Service()
|
||||
c := checkin.Model()
|
||||
service := checkin.Service()
|
||||
c.Failing = true
|
||||
fail := &types.Failure{
|
||||
Issue: fmt.Sprintf("Checkin %v was not reported %v ago, it expects a request every %v", c.Name, utils.FormatDuration(c.Expected()), utils.FormatDuration(c.Period())),
|
||||
|
|
|
@ -18,7 +18,7 @@ type Checkiner interface {
|
|||
Hits() *CheckinHitObj
|
||||
Failures() *FailureObj
|
||||
Model() *types.Checkin
|
||||
Object() *CheckinObj
|
||||
Service() *ServiceObj
|
||||
}
|
||||
|
||||
func (c *CheckinObj) BeforeCreate() (err error) {
|
||||
|
@ -67,11 +67,11 @@ func AllCheckins() []*CheckinObj {
|
|||
|
||||
func (s *CheckinObj) Service() *ServiceObj {
|
||||
var srv *types.Service
|
||||
q := database.Checkins().Where("service = ?", s.ServiceId)
|
||||
q := database.Services().Where("id = ?", s.ServiceId)
|
||||
q.Find(&srv)
|
||||
return &ServiceObj{
|
||||
Service: srv,
|
||||
o: wrapObject(srv.Id, srv, q),
|
||||
o: wrapObject(s.ServiceId, srv, q),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,10 +90,6 @@ func (c *CheckinObj) Model() *types.Checkin {
|
|||
return c.Checkin
|
||||
}
|
||||
|
||||
func (c *CheckinObj) Object() *CheckinObj {
|
||||
return c
|
||||
}
|
||||
|
||||
// Period will return the duration of the Checkin interval
|
||||
func (c *CheckinObj) Period() time.Duration {
|
||||
duration, _ := time.ParseDuration(fmt.Sprintf("%vs", c.Interval))
|
||||
|
|
|
@ -52,6 +52,16 @@ func (c *CheckinHit) BeforeCreate() (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (s *Checkin) Expected() time.Duration {
|
||||
last := s.LastHit
|
||||
now := time.Now().UTC()
|
||||
return time.Duration(now.Second() - last.Second())
|
||||
}
|
||||
|
||||
func (s *Checkin) Period() time.Duration {
|
||||
return time.Duration(s.Interval) * time.Second
|
||||
}
|
||||
|
||||
// Start will create a channel for the checkin checking go routine
|
||||
func (s *Checkin) Start() {
|
||||
s.Running = make(chan bool)
|
||||
|
|
Loading…
Reference in New Issue