followup fixes for new weighted build-queue

This commit is contained in:
Giovanni Harting 2022-02-19 19:39:48 +01:00
parent ba159e0a72
commit 270889bf5c
4 changed files with 38 additions and 6 deletions

11
main.go
View File

@ -390,6 +390,15 @@ func (b *BuildManager) syncWorker(ctx context.Context) error {
var slowQueue []*ProtoPackage
for _, pkg := range queue {
eligible, err := pkg.isEligible(ctx)
if err != nil {
log.Warningf("Unable to determine package status for package %s: %v", pkg.Pkgbase, err)
}
if !eligible {
log.Debugf("skipped package %s (%v)", pkg.Pkgbase, err)
continue
}
if pkg.Priority() >= float64(conf.Build.SlowQueueThreshold) {
slowQueue = append(slowQueue, pkg)
} else {
@ -397,7 +406,7 @@ func (b *BuildManager) syncWorker(ctx context.Context) error {
}
}
if len(fastQueue) == 0 {
if len(fastQueue) > 0 && len(slowQueue) > 0 {
log.Infof("Skipping slowQueue=%d in favor of fastQueue=%d", len(slowQueue), len(fastQueue))
slowQueue = []*ProtoPackage{}
}

View File

@ -37,7 +37,7 @@ type ProtoPackage struct {
DbPackage *ent.DbPackage
}
func (p ProtoPackage) isEligible(ctx context.Context) (bool, error) {
func (p *ProtoPackage) isEligible(ctx context.Context) (bool, error) {
if err := p.genSrcinfo(); err != nil {
return false, fmt.Errorf("error generating SRCINFO: %w", err)
}
@ -77,7 +77,7 @@ func (p ProtoPackage) isEligible(ctx context.Context) (bool, error) {
p.DbPackage = p.DbPackage.Update().SetUpdated(time.Now()).SetVersion(p.Version).
SetPackages(packages2slice(p.Srcinfo.Packages)).SetStatus(p.DbPackage.Status).
SetSkipReason(p.DbPackage.SkipReason).SetHash(p.Hash).SaveX(ctx)
return false, nil
return false, fmt.Errorf("skipped package: %s", p.DbPackage.SkipReason)
} else {
p.DbPackage = p.DbPackage.Update().SetUpdated(time.Now()).SetPackages(packages2slice(p.Srcinfo.Packages)).SetVersion(p.Version).SaveX(ctx)
}
@ -300,11 +300,15 @@ func (p *ProtoPackage) build(ctx context.Context) (time.Duration, error) {
}
func (p *ProtoPackage) Priority() float64 {
if p.DbPackage == nil {
return 0
}
if p.DbPackage.BuildTimeEnd.IsZero() {
return 0
} else {
time := p.DbPackage.BuildTimeEnd.Sub(p.DbPackage.BuildTimeStart)
return time.Minutes()
nTime := p.DbPackage.BuildTimeEnd.Sub(p.DbPackage.BuildTimeStart)
return nTime.Minutes()
}
}

18
rm_chroot.py Normal file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python3
import os
import sys
from pathlib import Path
SAVE_PATH = "/path/to/workdir"
try:
chroot_abs = Path(sys.argv[1]).resolve(True)
except:
print("path does not resolve")
sys.exit(1)
if str(chroot_abs).startswith(SAVE_PATH):
os.system("rm -rf " + str(chroot_abs))
else:
sys.exit(2)

View File

@ -168,7 +168,8 @@ func cleanBuildDir(dir string, chrootDir string) error {
if chrootDir != "" {
if stat, err := os.Stat(chrootDir); err == nil && stat.IsDir() {
err = os.RemoveAll(chrootDir)
rmCmd := exec.Command("rm_chroot.py", chrootDir)
_, err := rmCmd.CombinedOutput()
if err != nil {
return err
}