statping/types/failures/samples.go

58 lines
1.1 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package failures
import (
"fmt"
2020-03-09 18:17:55 +00:00
"github.com/statping/statping/types"
"github.com/statping/statping/utils"
2020-03-04 10:29:00 +00:00
"time"
2020-03-06 09:33:46 +00:00
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/mattn/go-sqlite3"
2020-03-04 10:29:00 +00:00
)
var (
log = utils.Log
)
2020-03-04 10:29:00 +00:00
func Samples() error {
2020-03-06 22:18:06 +00:00
createdAt := utils.Now().Add(-3 * types.Day)
2020-03-04 10:29:00 +00:00
2020-03-04 14:20:47 +00:00
for i := int64(1); i <= 4; i++ {
tx := db.Begin()
2020-03-04 10:29:00 +00:00
2020-03-10 08:49:57 +00:00
f1 := &Failure{
Service: i,
Issue: "Server failure",
CreatedAt: utils.Now().Add(-time.Duration(3*i) * 86400),
}
f1.Create()
f2 := &Failure{
Service: i,
Issue: "Server failure",
CreatedAt: utils.Now().Add(-time.Duration(5*i) * 12400),
}
f2.Create()
2020-03-09 15:15:15 +00:00
log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 400))
2020-03-04 10:29:00 +00:00
for fi := 0.; fi <= float64(400); fi++ {
createdAt = createdAt.Add(35 * time.Minute)
failure := &Failure{
Service: i,
Issue: "testing right here",
CreatedAt: createdAt.UTC(),
2020-03-04 10:29:00 +00:00
}
tx = tx.Create(&failure)
}
if err := tx.Commit().Error(); err != nil {
log.Error(err)
return err
}
2020-03-04 10:29:00 +00:00
}
2020-03-04 14:20:47 +00:00
2020-03-09 15:15:15 +00:00
return nil
2020-03-04 10:29:00 +00:00
}