statping/types/failures/samples.go

43 lines
730 B
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package failures
import (
"fmt"
"github.com/hunterlong/statping/types"
"github.com/prometheus/common/log"
2020-03-04 14:20:47 +00:00
"sync"
2020-03-04 10:29:00 +00:00
"time"
)
2020-03-04 14:20:47 +00:00
func Samples() {
tx := DB().Begin()
sg := new(sync.WaitGroup)
2020-03-04 10:29:00 +00:00
createdAt := time.Now().Add(-1 * types.Month)
2020-03-04 14:20:47 +00:00
for i := int64(1); i <= 4; i++ {
sg.Add(1)
2020-03-04 10:29:00 +00:00
2020-03-04 14:20:47 +00:00
log.Infoln(fmt.Sprintf("Adding %v Failure records to service", 730))
2020-03-04 10:29:00 +00:00
2020-03-04 14:20:47 +00:00
go func() {
defer sg.Done()
for fi := 0.; fi <= float64(730); fi++ {
createdAt = createdAt.Add(2 * time.Minute)
failure := &Failure{
Service: i,
Issue: "testing right here",
CreatedAt: createdAt.UTC(),
}
tx = tx.Create(&failure)
2020-03-04 10:29:00 +00:00
}
2020-03-04 14:20:47 +00:00
}()
}
sg.Wait()
2020-03-04 10:29:00 +00:00
2020-03-04 14:20:47 +00:00
if err := tx.Commit().Error(); err != nil {
log.Error(err)
2020-03-04 10:29:00 +00:00
}
2020-03-04 14:20:47 +00:00
2020-03-04 10:29:00 +00:00
}