Skip to content

Commit

Permalink
remove .Online from notifiers and toggle service.Online when needed. f…
Browse files Browse the repository at this point in the history
…ixes statping#118
  • Loading branch information
tufanbarisyildirim committed Aug 15, 2019
1 parent 85b4129 commit 30a1216
Show file tree
Hide file tree
Showing 23 changed files with 2,155 additions and 962 deletions.
6 changes: 3 additions & 3 deletions core/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ func (s *Service) checkHttp(record bool) *Service {
}
return s
}
s.Online = true
if record {
recordSuccess(s)
}
Expand All @@ -252,7 +251,6 @@ func (s *Service) checkHttp(record bool) *Service {

// recordSuccess will create a new 'hit' record in the database for a successful/online service
func recordSuccess(s *Service) {
s.Online = true
s.LastOnline = utils.Timezoner(time.Now().UTC(), CoreApp.Timezone)
hit := &types.Hit{
Service: s.Id,
Expand All @@ -263,11 +261,11 @@ func recordSuccess(s *Service) {
utils.Log(1, fmt.Sprintf("Service %v Successful Response: %0.2f ms | Lookup in: %0.2f ms", s.Name, hit.Latency*1000, hit.PingTime*1000))
s.CreateHit(hit)
notifier.OnSuccess(s.Service)
s.Online = true
}

// recordFailure will create a new 'Failure' record in the database for a offline service
func recordFailure(s *Service, issue string) {
s.Online = false
fail := &Failure{&types.Failure{
Service: s.Id,
Issue: issue,
Expand All @@ -278,4 +276,6 @@ func recordFailure(s *Service, issue string) {
utils.Log(2, fmt.Sprintf("Service %v Failing: %v | Lookup in: %0.2f ms", s.Name, issue, fail.PingTime*1000))
s.CreateFailure(fail)
notifier.OnFailure(s.Service, fail.Failure)
s.Online = false

}
2 changes: 2 additions & 0 deletions core/notifier/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func OnFailure(s *types.Service, f *types.Failure) {
comm.(BasicEvents).OnFailure(s, f)
}
}

}

// OnSuccess will be triggered when a service is successful - BasicEvents interface
Expand All @@ -51,6 +52,7 @@ func OnSuccess(s *types.Service) {
comm.(BasicEvents).OnSuccess(s)
}
}

}

// OnNewService is triggered when a new service is created - ServiceEvents interface
Expand Down
1 change: 0 additions & 1 deletion core/notifier/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ type Notification struct {
Delay time.Duration `gorm:"-" json:"delay,string"`
Queue []*QueueData `gorm:"-" json:"-"`
Running chan bool `gorm:"-" json:"-"`
Online bool `gorm:"-" json:"online"`
testable bool `gorm:"-" json:"testable"`
}

Expand Down
Loading

0 comments on commit 30a1216

Please sign in to comment.