pull/78/head
Hunter Long 2018-10-02 01:39:47 -07:00
parent bede064e57
commit 514dcff4be
6 changed files with 13 additions and 14 deletions

View File

@ -4,7 +4,7 @@ os:
language: go
go:
- "1.10.3"
- "1.11"
go_import_path: github.com/hunterlong/statup

6
Gopkg.lock generated
View File

@ -296,18 +296,18 @@
"md4",
]
pruneopts = "UT"
revision = "0e37d006457bf46f9e6692014ba72ef82c33022c"
revision = "e3636079e1a4c1f337f212cc5cd2aca108f6c900"
[[projects]]
branch = "master"
digest = "1:6fb1dd382722f93fcf7c52ff631f7b899d8c5d54314d88d42dd1f4e5ac404a30"
digest = "1:6f82ed211591ecb407897ca46ff6149d618223088aecad72675804f106033629"
name = "golang.org/x/sys"
packages = [
"unix",
"windows",
]
pruneopts = "UT"
revision = "c2ed4eda69e7f62900806e4cd6e45f0429f859fa"
revision = "e4b3c5e9061176387e7cea65e4dc5853801f3fb7"
[[projects]]
digest = "1:c25289f43ac4a68d88b02245742347c94f1e108c534dda442188015ff80669b3"

View File

@ -47,14 +47,6 @@ func FindCheckin(api string) *types.Checkin {
return nil
}
func (s *Service) AllCheckins() []*types.Checkin {
var checkins []*types.Checkin
col := checkinDB().Where("service = ?", s.Id).Order("id desc")
col.Find(&checkins)
s.Checkins = checkins
return checkins
}
func (u *Checkin) Create() (int64, error) {
u.CreatedAt = time.Now()
row := checkinDB().Create(u)

View File

@ -69,7 +69,7 @@ func checkinDB() *gorm.DB {
// HitsBetween returns the gorm database query for a collection of service hits between a time range
func (s *Service) HitsBetween(t1, t2 time.Time, group string) *gorm.DB {
selector := Dbtimestamp(group)
return DbSession.Debug().Model(&types.Hit{}).Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.Format(types.TIME_DAY), t2.Format(types.TIME_DAY)).Order("timeframe asc", false).Group("timeframe")
return DbSession.Model(&types.Hit{}).Select(selector).Where("service = ? AND created_at BETWEEN ? AND ?", s.Id, t1.Format(types.TIME_DAY), t2.Format(types.TIME_DAY)).Order("timeframe asc", false).Group("timeframe")
}
func CloseDB() {

View File

@ -49,6 +49,12 @@ func SelectService(id int64) *Service {
return nil
}
func (s *Service) Checkins() []*types.Checkin {
var hits []*types.Checkin
servicesDB().Where("service = ?", s.Id).Scan(&hits)
return hits
}
// SelectAllServices returns a slice of *core.Service to be store on []*core.Services, should only be called once on startup.
func (c *Core) SelectAllServices() ([]*Service, error) {
var services []*Service
@ -60,7 +66,7 @@ func (c *Core) SelectAllServices() ([]*Service, error) {
CoreApp.Services = nil
for _, service := range services {
service.Start()
service.AllCheckins()
service.Checkins()
service.AllFailures()
CoreApp.Services = append(CoreApp.Services, service)
}

View File

@ -56,6 +56,7 @@ type ServiceInterface interface {
Create(bool) (int64, error)
Update(bool) error
Delete() error
Checkins() []*Checkin
}
// Start will create a channel for the service checking go routine