forked from ALHP/ALHP.GO
removed status page code, provided by api now
This commit is contained in:
186
buildmanager.go
186
buildmanager.go
@@ -7,11 +7,9 @@ import (
|
||||
"github.com/c2h5oh/datasize"
|
||||
"github.com/sethvargo/go-retry"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"html/template"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"somegit.dev/ALHP/ALHP.GO/ent"
|
||||
"somegit.dev/ALHP/ALHP.GO/ent/dbpackage"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -149,190 +147,6 @@ func (b *BuildManager) buildQueue(ctx context.Context, queue []*ProtoPackage) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BuildManager) htmlWorker(ctx context.Context) {
|
||||
type Pkg struct {
|
||||
Pkgbase string
|
||||
Status string
|
||||
Class string
|
||||
Skip string
|
||||
Version string
|
||||
Svn2GitVersion string
|
||||
BuildDate string
|
||||
BuildDuration time.Duration
|
||||
BuildMemory *string
|
||||
Checked string
|
||||
Log string
|
||||
LTO bool
|
||||
LTOUnknown bool
|
||||
LTODisabled bool
|
||||
LTOAutoDisabled bool
|
||||
DebugSym bool
|
||||
DebugSymNotAvailable bool
|
||||
DebugSymUnknown bool
|
||||
}
|
||||
|
||||
type Repo struct {
|
||||
Name string
|
||||
Packages []Pkg
|
||||
}
|
||||
|
||||
type March struct {
|
||||
Name string
|
||||
Repos []Repo
|
||||
}
|
||||
|
||||
type tpl struct {
|
||||
March []March
|
||||
Generated string
|
||||
Latest int
|
||||
Failed int
|
||||
Skipped int
|
||||
Queued int
|
||||
LTOEnabled int
|
||||
LTOUnknown int
|
||||
LTODisabled int
|
||||
}
|
||||
|
||||
for {
|
||||
gen := &tpl{}
|
||||
|
||||
for _, march := range conf.March {
|
||||
addMarch := March{
|
||||
Name: march,
|
||||
}
|
||||
|
||||
for _, repo := range conf.Repos {
|
||||
addRepo := Repo{
|
||||
Name: repo,
|
||||
}
|
||||
|
||||
pkgs := db.DBPackage.Query().Order(ent.Asc(dbpackage.FieldPkgbase)).
|
||||
Where(dbpackage.MarchEQ(march), dbpackage.RepositoryEQ(dbpackage.Repository(repo))).AllX(ctx)
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
addPkg := Pkg{
|
||||
Pkgbase: pkg.Pkgbase,
|
||||
Status: strings.ToUpper(pkg.Status.String()),
|
||||
Class: statusID2string(pkg.Status),
|
||||
Skip: pkg.SkipReason,
|
||||
Version: pkg.RepoVersion,
|
||||
Svn2GitVersion: pkg.Version,
|
||||
}
|
||||
|
||||
if pkg.STime != nil && pkg.UTime != nil {
|
||||
addPkg.BuildDuration = time.Duration(*pkg.STime+*pkg.UTime) * time.Second
|
||||
}
|
||||
|
||||
if !pkg.BuildTimeStart.IsZero() {
|
||||
addPkg.BuildDate = pkg.BuildTimeStart.UTC().Format(time.RFC1123)
|
||||
}
|
||||
|
||||
if !pkg.Updated.IsZero() {
|
||||
addPkg.Checked = pkg.Updated.UTC().Format(time.RFC1123)
|
||||
}
|
||||
|
||||
if pkg.Status == dbpackage.StatusFailed {
|
||||
addPkg.Log = fmt.Sprintf("%s/%s/%s.log", logDir, pkg.March, pkg.Pkgbase)
|
||||
}
|
||||
|
||||
if pkg.MaxRss != nil {
|
||||
hrSize := (datasize.ByteSize(*pkg.MaxRss) * datasize.KB).HumanReadable()
|
||||
addPkg.BuildMemory = &hrSize
|
||||
}
|
||||
|
||||
switch pkg.Lto {
|
||||
case dbpackage.LtoUnknown:
|
||||
if pkg.Status != dbpackage.StatusSkipped && pkg.Status != dbpackage.StatusFailed {
|
||||
addPkg.LTOUnknown = true
|
||||
}
|
||||
case dbpackage.LtoEnabled:
|
||||
addPkg.LTO = true
|
||||
case dbpackage.LtoDisabled:
|
||||
addPkg.LTODisabled = true
|
||||
case dbpackage.LtoAutoDisabled:
|
||||
addPkg.LTOAutoDisabled = true
|
||||
}
|
||||
|
||||
switch pkg.DebugSymbols {
|
||||
case dbpackage.DebugSymbolsUnknown:
|
||||
if pkg.Status != dbpackage.StatusSkipped && pkg.Status != dbpackage.StatusFailed {
|
||||
addPkg.DebugSymUnknown = true
|
||||
}
|
||||
case dbpackage.DebugSymbolsAvailable:
|
||||
addPkg.DebugSym = true
|
||||
case dbpackage.DebugSymbolsNotAvailable:
|
||||
addPkg.DebugSymNotAvailable = true
|
||||
}
|
||||
|
||||
addRepo.Packages = append(addRepo.Packages, addPkg)
|
||||
}
|
||||
addMarch.Repos = append(addMarch.Repos, addRepo)
|
||||
}
|
||||
gen.March = append(gen.March, addMarch)
|
||||
}
|
||||
|
||||
gen.Generated = time.Now().UTC().Format(time.RFC1123)
|
||||
|
||||
var v []struct {
|
||||
Status dbpackage.Status `json:"status"`
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
db.DBPackage.Query().GroupBy(dbpackage.FieldStatus).Aggregate(ent.Count()).ScanX(ctx, &v)
|
||||
|
||||
for _, c := range v {
|
||||
switch c.Status { //nolint:exhaustive
|
||||
case dbpackage.StatusFailed:
|
||||
gen.Failed = c.Count
|
||||
case dbpackage.StatusSkipped:
|
||||
gen.Skipped = c.Count
|
||||
case dbpackage.StatusLatest:
|
||||
gen.Latest = c.Count
|
||||
case dbpackage.StatusQueued:
|
||||
gen.Queued = c.Count
|
||||
}
|
||||
}
|
||||
|
||||
var v2 []struct {
|
||||
Status dbpackage.Lto `json:"lto"` //nolint:tagliatelle
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
db.DBPackage.Query().Where(dbpackage.StatusNEQ(dbpackage.StatusSkipped)).
|
||||
GroupBy(dbpackage.FieldLto).Aggregate(ent.Count()).ScanX(ctx, &v2)
|
||||
|
||||
for _, c := range v2 {
|
||||
switch c.Status {
|
||||
case dbpackage.LtoUnknown:
|
||||
gen.LTOUnknown = c.Count
|
||||
case dbpackage.LtoDisabled, dbpackage.LtoAutoDisabled:
|
||||
gen.LTODisabled += c.Count
|
||||
case dbpackage.LtoEnabled:
|
||||
gen.LTOEnabled = c.Count
|
||||
}
|
||||
}
|
||||
|
||||
statusTpl, err := template.ParseFiles("tpl/packages.html")
|
||||
if err != nil {
|
||||
log.Warningf("[HTML] error parsing template file: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(filepath.Join(conf.Basedir.Repo, "packages.html"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
log.Warningf("[HTML] error opening output file: %v", err)
|
||||
continue
|
||||
}
|
||||
err = statusTpl.Execute(f, gen)
|
||||
if err != nil {
|
||||
log.Warningf("[HTML] error filling template: %v", err)
|
||||
}
|
||||
_ = f.Close()
|
||||
|
||||
time.Sleep(time.Minute * 5)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BuildManager) repoWorker(repo string) {
|
||||
for {
|
||||
select {
|
||||
|
Reference in New Issue
Block a user