mirror of https://github.com/statping/statping
api failures in correct order and count
parent
015a9bb869
commit
e5785f0ea8
|
@ -28,16 +28,23 @@ type failure struct {
|
|||
*types.Failure
|
||||
}
|
||||
|
||||
const (
|
||||
limitedFailures = 64
|
||||
)
|
||||
|
||||
// CreateFailure will create a new failure record for a service
|
||||
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) {
|
||||
f := fail.(*failure)
|
||||
f.Service = s.Id
|
||||
s.Failures = append(s.Failures, f.Select())
|
||||
row := failuresDB().Create(f)
|
||||
if row.Error != nil {
|
||||
utils.Log(3, row.Error)
|
||||
return 0, row.Error
|
||||
}
|
||||
s.Failures = append(s.Failures, f.Select())
|
||||
if len(s.Failures) >= limitedFailures {
|
||||
s.Failures = s.Failures[1:]
|
||||
}
|
||||
return f.Id, row.Error
|
||||
}
|
||||
|
||||
|
@ -50,9 +57,6 @@ func (s *Service) AllFailures() []*failure {
|
|||
utils.Log(3, fmt.Sprintf("Issue getting failures for service %v, %v", s.Name, err))
|
||||
return nil
|
||||
}
|
||||
for _, f := range fails {
|
||||
s.Failures = append(s.Failures, f.Select())
|
||||
}
|
||||
return fails
|
||||
}
|
||||
|
||||
|
@ -68,7 +72,7 @@ func (s *Service) DeleteFailures() {
|
|||
// LimitedFailures will return the last amount of failures from a service
|
||||
func (s *Service) LimitedFailures(amount int64) []*failure {
|
||||
var failArr []*failure
|
||||
failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount).Find(&failArr)
|
||||
failuresDB().Where("service = ?", s.Id).Order("id desc").Limit(amount).Find(&failArr)
|
||||
return failArr
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ func SelectServices() []*Service {
|
|||
var services []*Service
|
||||
servicesDB().Find(&services).Order("order_id desc")
|
||||
for _, service := range services {
|
||||
failures := service.LimitedFailures(100)
|
||||
failures := service.LimitedFailures(limitedFailures)
|
||||
service.Failures = nil
|
||||
for _, fail := range failures {
|
||||
utils.Log(1, fail)
|
||||
|
@ -106,7 +106,7 @@ func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
|
|||
service.Start()
|
||||
service.CheckinProcess()
|
||||
}
|
||||
failures := service.LimitedFailures(100)
|
||||
failures := service.LimitedFailures(limitedFailures)
|
||||
service.Failures = nil
|
||||
for _, fail := range failures {
|
||||
service.Failures = append(service.Failures, fail.Select())
|
||||
|
|
Loading…
Reference in New Issue