forked from ALHP/ALHP.GO
prepare for better stats
This commit is contained in:
@@ -62,6 +62,8 @@ func ValidColumn(column string) bool {
|
|||||||
var (
|
var (
|
||||||
// PkgbaseValidator is a validator for the "pkgbase" field. It is called by the builders before save.
|
// PkgbaseValidator is a validator for the "pkgbase" field. It is called by the builders before save.
|
||||||
PkgbaseValidator func(string) error
|
PkgbaseValidator func(string) error
|
||||||
|
// DefaultStatus holds the default value on creation for the "status" field.
|
||||||
|
DefaultStatus int
|
||||||
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
StatusValidator func(int) error
|
StatusValidator func(int) error
|
||||||
// RepositoryValidator is a validator for the "repository" field. It is called by the builders before save.
|
// RepositoryValidator is a validator for the "repository" field. It is called by the builders before save.
|
||||||
|
@@ -363,20 +363,6 @@ func StatusLTE(v int) predicate.DbPackage {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StatusIsNil applies the IsNil predicate on the "status" field.
|
|
||||||
func StatusIsNil() predicate.DbPackage {
|
|
||||||
return predicate.DbPackage(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.IsNull(s.C(FieldStatus)))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusNotNil applies the NotNil predicate on the "status" field.
|
|
||||||
func StatusNotNil() predicate.DbPackage {
|
|
||||||
return predicate.DbPackage(func(s *sql.Selector) {
|
|
||||||
s.Where(sql.NotNull(s.C(FieldStatus)))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// SkipReasonEQ applies the EQ predicate on the "skip_reason" field.
|
// SkipReasonEQ applies the EQ predicate on the "skip_reason" field.
|
||||||
func SkipReasonEQ(v string) predicate.DbPackage {
|
func SkipReasonEQ(v string) predicate.DbPackage {
|
||||||
return predicate.DbPackage(func(s *sql.Selector) {
|
return predicate.DbPackage(func(s *sql.Selector) {
|
||||||
|
@@ -153,6 +153,7 @@ func (dpc *DbPackageCreate) Save(ctx context.Context) (*DbPackage, error) {
|
|||||||
err error
|
err error
|
||||||
node *DbPackage
|
node *DbPackage
|
||||||
)
|
)
|
||||||
|
dpc.defaults()
|
||||||
if len(dpc.hooks) == 0 {
|
if len(dpc.hooks) == 0 {
|
||||||
if err = dpc.check(); err != nil {
|
if err = dpc.check(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -191,6 +192,14 @@ func (dpc *DbPackageCreate) SaveX(ctx context.Context) *DbPackage {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defaults sets the default values of the builder before save.
|
||||||
|
func (dpc *DbPackageCreate) defaults() {
|
||||||
|
if _, ok := dpc.mutation.Status(); !ok {
|
||||||
|
v := dbpackage.DefaultStatus
|
||||||
|
dpc.mutation.SetStatus(v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check runs all checks and user-defined validators on the builder.
|
// check runs all checks and user-defined validators on the builder.
|
||||||
func (dpc *DbPackageCreate) check() error {
|
func (dpc *DbPackageCreate) check() error {
|
||||||
if _, ok := dpc.mutation.Pkgbase(); !ok {
|
if _, ok := dpc.mutation.Pkgbase(); !ok {
|
||||||
@@ -201,6 +210,9 @@ func (dpc *DbPackageCreate) check() error {
|
|||||||
return &ValidationError{Name: "pkgbase", err: fmt.Errorf("ent: validator failed for field \"pkgbase\": %w", err)}
|
return &ValidationError{Name: "pkgbase", err: fmt.Errorf("ent: validator failed for field \"pkgbase\": %w", err)}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if _, ok := dpc.mutation.Status(); !ok {
|
||||||
|
return &ValidationError{Name: "status", err: errors.New("ent: missing required field \"status\"")}
|
||||||
|
}
|
||||||
if v, ok := dpc.mutation.Status(); ok {
|
if v, ok := dpc.mutation.Status(); ok {
|
||||||
if err := dbpackage.StatusValidator(v); err != nil {
|
if err := dbpackage.StatusValidator(v); err != nil {
|
||||||
return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)}
|
return &ValidationError{Name: "status", err: fmt.Errorf("ent: validator failed for field \"status\": %w", err)}
|
||||||
@@ -359,6 +371,7 @@ func (dpcb *DbPackageCreateBulk) Save(ctx context.Context) ([]*DbPackage, error)
|
|||||||
for i := range dpcb.builders {
|
for i := range dpcb.builders {
|
||||||
func(i int, root context.Context) {
|
func(i int, root context.Context) {
|
||||||
builder := dpcb.builders[i]
|
builder := dpcb.builders[i]
|
||||||
|
builder.defaults()
|
||||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||||
mutation, ok := m.(*DbPackageMutation)
|
mutation, ok := m.(*DbPackageMutation)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@@ -60,12 +60,6 @@ func (dpu *DbPackageUpdate) AddStatus(i int) *DbPackageUpdate {
|
|||||||
return dpu
|
return dpu
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearStatus clears the value of the "status" field.
|
|
||||||
func (dpu *DbPackageUpdate) ClearStatus() *DbPackageUpdate {
|
|
||||||
dpu.mutation.ClearStatus()
|
|
||||||
return dpu
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSkipReason sets the "skip_reason" field.
|
// SetSkipReason sets the "skip_reason" field.
|
||||||
func (dpu *DbPackageUpdate) SetSkipReason(s string) *DbPackageUpdate {
|
func (dpu *DbPackageUpdate) SetSkipReason(s string) *DbPackageUpdate {
|
||||||
dpu.mutation.SetSkipReason(s)
|
dpu.mutation.SetSkipReason(s)
|
||||||
@@ -337,12 +331,6 @@ func (dpu *DbPackageUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
|||||||
Column: dbpackage.FieldStatus,
|
Column: dbpackage.FieldStatus,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if dpu.mutation.StatusCleared() {
|
|
||||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeInt,
|
|
||||||
Column: dbpackage.FieldStatus,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if value, ok := dpu.mutation.SkipReason(); ok {
|
if value, ok := dpu.mutation.SkipReason(); ok {
|
||||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
Type: field.TypeString,
|
Type: field.TypeString,
|
||||||
@@ -494,12 +482,6 @@ func (dpuo *DbPackageUpdateOne) AddStatus(i int) *DbPackageUpdateOne {
|
|||||||
return dpuo
|
return dpuo
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearStatus clears the value of the "status" field.
|
|
||||||
func (dpuo *DbPackageUpdateOne) ClearStatus() *DbPackageUpdateOne {
|
|
||||||
dpuo.mutation.ClearStatus()
|
|
||||||
return dpuo
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSkipReason sets the "skip_reason" field.
|
// SetSkipReason sets the "skip_reason" field.
|
||||||
func (dpuo *DbPackageUpdateOne) SetSkipReason(s string) *DbPackageUpdateOne {
|
func (dpuo *DbPackageUpdateOne) SetSkipReason(s string) *DbPackageUpdateOne {
|
||||||
dpuo.mutation.SetSkipReason(s)
|
dpuo.mutation.SetSkipReason(s)
|
||||||
@@ -795,12 +777,6 @@ func (dpuo *DbPackageUpdateOne) sqlSave(ctx context.Context) (_node *DbPackage,
|
|||||||
Column: dbpackage.FieldStatus,
|
Column: dbpackage.FieldStatus,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if dpuo.mutation.StatusCleared() {
|
|
||||||
_spec.Fields.Clear = append(_spec.Fields.Clear, &sqlgraph.FieldSpec{
|
|
||||||
Type: field.TypeInt,
|
|
||||||
Column: dbpackage.FieldStatus,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if value, ok := dpuo.mutation.SkipReason(); ok {
|
if value, ok := dpuo.mutation.SkipReason(); ok {
|
||||||
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
_spec.Fields.Set = append(_spec.Fields.Set, &sqlgraph.FieldSpec{
|
||||||
Type: field.TypeString,
|
Type: field.TypeString,
|
||||||
|
@@ -13,7 +13,7 @@ var (
|
|||||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||||
{Name: "pkgbase", Type: field.TypeString, Unique: true},
|
{Name: "pkgbase", Type: field.TypeString, Unique: true},
|
||||||
{Name: "packages", Type: field.TypeJSON, Nullable: true},
|
{Name: "packages", Type: field.TypeJSON, Nullable: true},
|
||||||
{Name: "status", Type: field.TypeInt, Nullable: true},
|
{Name: "status", Type: field.TypeInt, Default: 6},
|
||||||
{Name: "skip_reason", Type: field.TypeString, Nullable: true},
|
{Name: "skip_reason", Type: field.TypeString, Nullable: true},
|
||||||
{Name: "repository", Type: field.TypeString},
|
{Name: "repository", Type: field.TypeString},
|
||||||
{Name: "march", Type: field.TypeString},
|
{Name: "march", Type: field.TypeString},
|
||||||
|
@@ -265,24 +265,10 @@ func (m *DbPackageMutation) AddedStatus() (r int, exists bool) {
|
|||||||
return *v, true
|
return *v, true
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearStatus clears the value of the "status" field.
|
|
||||||
func (m *DbPackageMutation) ClearStatus() {
|
|
||||||
m.status = nil
|
|
||||||
m.addstatus = nil
|
|
||||||
m.clearedFields[dbpackage.FieldStatus] = struct{}{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// StatusCleared returns if the "status" field was cleared in this mutation.
|
|
||||||
func (m *DbPackageMutation) StatusCleared() bool {
|
|
||||||
_, ok := m.clearedFields[dbpackage.FieldStatus]
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResetStatus resets all changes to the "status" field.
|
// ResetStatus resets all changes to the "status" field.
|
||||||
func (m *DbPackageMutation) ResetStatus() {
|
func (m *DbPackageMutation) ResetStatus() {
|
||||||
m.status = nil
|
m.status = nil
|
||||||
m.addstatus = nil
|
m.addstatus = nil
|
||||||
delete(m.clearedFields, dbpackage.FieldStatus)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSkipReason sets the "skip_reason" field.
|
// SetSkipReason sets the "skip_reason" field.
|
||||||
@@ -927,9 +913,6 @@ func (m *DbPackageMutation) ClearedFields() []string {
|
|||||||
if m.FieldCleared(dbpackage.FieldPackages) {
|
if m.FieldCleared(dbpackage.FieldPackages) {
|
||||||
fields = append(fields, dbpackage.FieldPackages)
|
fields = append(fields, dbpackage.FieldPackages)
|
||||||
}
|
}
|
||||||
if m.FieldCleared(dbpackage.FieldStatus) {
|
|
||||||
fields = append(fields, dbpackage.FieldStatus)
|
|
||||||
}
|
|
||||||
if m.FieldCleared(dbpackage.FieldSkipReason) {
|
if m.FieldCleared(dbpackage.FieldSkipReason) {
|
||||||
fields = append(fields, dbpackage.FieldSkipReason)
|
fields = append(fields, dbpackage.FieldSkipReason)
|
||||||
}
|
}
|
||||||
@@ -965,9 +948,6 @@ func (m *DbPackageMutation) ClearField(name string) error {
|
|||||||
case dbpackage.FieldPackages:
|
case dbpackage.FieldPackages:
|
||||||
m.ClearPackages()
|
m.ClearPackages()
|
||||||
return nil
|
return nil
|
||||||
case dbpackage.FieldStatus:
|
|
||||||
m.ClearStatus()
|
|
||||||
return nil
|
|
||||||
case dbpackage.FieldSkipReason:
|
case dbpackage.FieldSkipReason:
|
||||||
m.ClearSkipReason()
|
m.ClearSkipReason()
|
||||||
return nil
|
return nil
|
||||||
|
@@ -19,6 +19,8 @@ func init() {
|
|||||||
dbpackage.PkgbaseValidator = dbpackageDescPkgbase.Validators[0].(func(string) error)
|
dbpackage.PkgbaseValidator = dbpackageDescPkgbase.Validators[0].(func(string) error)
|
||||||
// dbpackageDescStatus is the schema descriptor for status field.
|
// dbpackageDescStatus is the schema descriptor for status field.
|
||||||
dbpackageDescStatus := dbpackageFields[2].Descriptor()
|
dbpackageDescStatus := dbpackageFields[2].Descriptor()
|
||||||
|
// dbpackage.DefaultStatus holds the default value on creation for the status field.
|
||||||
|
dbpackage.DefaultStatus = dbpackageDescStatus.Default.(int)
|
||||||
// dbpackage.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
// dbpackage.StatusValidator is a validator for the "status" field. It is called by the builders before save.
|
||||||
dbpackage.StatusValidator = dbpackageDescStatus.Validators[0].(func(int) error)
|
dbpackage.StatusValidator = dbpackageDescStatus.Validators[0].(func(int) error)
|
||||||
// dbpackageDescRepository is the schema descriptor for repository field.
|
// dbpackageDescRepository is the schema descriptor for repository field.
|
||||||
|
@@ -15,7 +15,7 @@ func (DbPackage) Fields() []ent.Field {
|
|||||||
return []ent.Field{
|
return []ent.Field{
|
||||||
field.String("pkgbase").NotEmpty().Immutable().Unique(),
|
field.String("pkgbase").NotEmpty().Immutable().Unique(),
|
||||||
field.Strings("packages").Optional(),
|
field.Strings("packages").Optional(),
|
||||||
field.Int("status").Optional().Min(0),
|
field.Int("status").Min(0).Default(6),
|
||||||
field.String("skip_reason").Optional(),
|
field.String("skip_reason").Optional(),
|
||||||
field.String("repository").NotEmpty(),
|
field.String("repository").NotEmpty(),
|
||||||
field.String("march").NotEmpty(),
|
field.String("march").NotEmpty(),
|
||||||
|
16
main.go
16
main.go
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"ALHP.go/ent"
|
"ALHP.go/ent"
|
||||||
"ALHP.go/ent/dbpackage"
|
"ALHP.go/ent/dbpackage"
|
||||||
|
"ALHP.go/ent/migrate"
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
@@ -45,6 +46,7 @@ const (
|
|||||||
QUEUED = iota
|
QUEUED = iota
|
||||||
BUILDING = iota
|
BUILDING = iota
|
||||||
LATEST = iota
|
LATEST = iota
|
||||||
|
UNKNOWN = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -829,6 +831,18 @@ func (b *BuildManager) syncWorker() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
b.buildWG.Wait()
|
b.buildWG.Wait()
|
||||||
|
|
||||||
|
/* TODO: Use `v` to print rudimentary stats
|
||||||
|
var v []struct {
|
||||||
|
Status int `json:"status"`
|
||||||
|
Count int `json:"count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
dbLock.RLock()
|
||||||
|
db.DbPackage.Query().GroupBy(dbpackage.FieldStatus).Aggregate(ent.Count()).ScanX(context.Background(), &v)
|
||||||
|
dbLock.RUnlock()
|
||||||
|
*/
|
||||||
|
|
||||||
for gitDir, gitURL := range conf.Svn2git {
|
for gitDir, gitURL := range conf.Svn2git {
|
||||||
gitPath := filepath.Join(conf.Basedir.Upstream, gitDir)
|
gitPath := filepath.Join(conf.Basedir.Upstream, gitDir)
|
||||||
|
|
||||||
@@ -927,7 +941,7 @@ func main() {
|
|||||||
check(dbSQLite.Close())
|
check(dbSQLite.Close())
|
||||||
}(db)
|
}(db)
|
||||||
|
|
||||||
if err := db.Schema.Create(context.Background()); err != nil {
|
if err := db.Schema.Create(context.Background(), migrate.WithDropIndex(true), migrate.WithDropColumn(true)); err != nil {
|
||||||
log.Panicf("Automigrate failed: %v", err)
|
log.Panicf("Automigrate failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user