cache updates - api updates

pull/94/head
Hunter Long 2018-11-08 17:41:51 -08:00
parent 9ffa5674b2
commit 015a9bb869
5 changed files with 49 additions and 38 deletions

View File

@ -18,6 +18,9 @@ PATH:=$(PATH)
# build all arch's and release Statup # build all arch's and release Statup
release: dev-deps build-all release: dev-deps build-all
# build and push the images to docker hub
docker: docker-build-all docker-publish-all
# test all versions of Statup, golang testing and then cypress UI testing # test all versions of Statup, golang testing and then cypress UI testing
test-all: dev-deps test test-all: dev-deps test

View File

@ -32,7 +32,7 @@ type failure struct {
func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) { func (s *Service) CreateFailure(fail types.FailureInterface) (int64, error) {
f := fail.(*failure) f := fail.(*failure)
f.Service = s.Id f.Service = s.Id
s.Failures = append(s.Failures, f) s.Failures = append(s.Failures, f.Select())
row := failuresDB().Create(f) row := failuresDB().Create(f)
if row.Error != nil { if row.Error != nil {
utils.Log(3, row.Error) utils.Log(3, row.Error)
@ -51,7 +51,7 @@ func (s *Service) AllFailures() []*failure {
return nil return nil
} }
for _, f := range fails { for _, f := range fails {
s.Failures = append(s.Failures, f) s.Failures = append(s.Failures, f.Select())
} }
return fails return fails
} }
@ -68,8 +68,7 @@ func (s *Service) DeleteFailures() {
// LimitedFailures will return the last amount of failures from a service // LimitedFailures will return the last amount of failures from a service
func (s *Service) LimitedFailures(amount int64) []*failure { func (s *Service) LimitedFailures(amount int64) []*failure {
var failArr []*failure var failArr []*failure
col := failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount) failuresDB().Where("service = ?", s.Id).Order("id asc").Limit(amount).Find(&failArr)
col.Find(&failArr)
return failArr return failArr
} }

View File

@ -78,6 +78,20 @@ func (s *Service) LimitedCheckins() []*Checkin {
return checkin return checkin
} }
func SelectServices() []*Service {
var services []*Service
servicesDB().Find(&services).Order("order_id desc")
for _, service := range services {
failures := service.LimitedFailures(100)
service.Failures = nil
for _, fail := range failures {
utils.Log(1, fail)
service.Failures = append(service.Failures, fail.Select())
}
}
return services
}
// SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup. // SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
func (c *Core) SelectAllServices(start bool) ([]*Service, error) { func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
var services []*Service var services []*Service
@ -95,7 +109,7 @@ func (c *Core) SelectAllServices(start bool) ([]*Service, error) {
failures := service.LimitedFailures(100) failures := service.LimitedFailures(100)
service.Failures = nil service.Failures = nil
for _, fail := range failures { for _, fail := range failures {
service.Failures = append(service.Failures, fail) service.Failures = append(service.Failures, fail.Select())
} }
CoreApp.Services = append(CoreApp.Services, service) CoreApp.Services = append(CoreApp.Services, service)
} }

View File

@ -214,12 +214,7 @@ func apiAllServicesHandler(w http.ResponseWriter, r *http.Request) {
sendUnauthorizedJson(w, r) sendUnauthorizedJson(w, r)
return return
} }
allServices := core.CoreApp.Services services := core.SelectServices()
var services []types.ServiceInterface
for _, s := range allServices {
service := s.Select()
services = append(services, core.ReturnService(service))
}
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(services) json.NewEncoder(w).Encode(services)
} }

View File

@ -47,7 +47,7 @@ type Service struct {
LastResponse string `gorm:"-" json:"-"` LastResponse string `gorm:"-" json:"-"`
LastStatusCode int `gorm:"-" json:"status_code"` LastStatusCode int `gorm:"-" json:"status_code"`
LastOnline time.Time `gorm:"-" json:"last_online"` LastOnline time.Time `gorm:"-" json:"last_online"`
Failures []FailureInterface `gorm:"-" json:"failures,omitempty"` Failures []*Failure `gorm:"-" json:"failures,omitempty"`
} }
type ServiceInterface interface { type ServiceInterface interface {