statping/types/failures/samples.go

52 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-05-19 03:46:54 +00:00
gormbulk "github.com/t-tiger/gorm-bulk-insert/v2"
2020-03-04 10:29:00 +00:00
"time"
)
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++ {
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
2020-05-19 03:46:54 +00:00
var records []interface{}
for fi := 0.; fi <= float64(400); fi++ {
failure := &Failure{
Service: i,
Issue: "testing right here",
CreatedAt: createdAt.UTC(),
2020-03-04 10:29:00 +00:00
}
2020-05-19 03:46:54 +00:00
records = append(records, failure)
2020-04-16 09:57:00 +00:00
createdAt = createdAt.Add(35 * time.Minute)
}
if err := gormbulk.BulkInsert(db.GormDB(), records, db.ChunkSize()); err != nil {
log.Error(err)
return err
}
2020-03-04 10:29:00 +00:00
}
2020-03-09 15:15:15 +00:00
return nil
2020-03-04 10:29:00 +00:00
}