Fix broken i386 queue

This commit is contained in:
ferreo 2024-08-10 14:06:31 +01:00
parent b766d5ef80
commit 8e8ed73381
3 changed files with 89 additions and 65 deletions

View File

@ -2,6 +2,7 @@ package buildqueue
import (
"brunel/domain"
"fmt"
"strings"
"errors"
@ -11,42 +12,8 @@ import (
var queue = haxmap.New[string, domain.BuildQueueItem]()
func Add(buildItem domain.BuildQueueItem) error {
if strings.Contains(buildItem.BuildVersion, "+b") {
buildItem.BuildVersion = strings.Split(buildItem.BuildVersion, "+b")[0]
}
if _, ok := queue.Get(buildItem.Source.Name); ok {
return errors.New("package already in queue")
}
queue.Set(buildItem.Source.Name, buildItem)
return nil
}
func Get(name string) (domain.BuildQueueItem, bool) {
item, ok := queue.Get(name)
return item, ok
}
func Remove(name string) error {
_, ok := queue.Get(name)
if !ok {
return errors.New("package not in queue")
}
queue.Del(name)
return nil
}
func Update(buildItem domain.BuildQueueItem) error {
item, ok := queue.Get(buildItem.Source.Name)
if !ok {
return errors.New("package not in queue")
}
if item.Status == domain.Building {
return errors.New("package is already building")
}
queue.Set(buildItem.Source.Name, buildItem)
return nil
func getQueueKey(name string, buildType domain.BuildType) string {
return fmt.Sprintf("%s_%s", name, buildType)
}
func GetQueue() *haxmap.Map[string, domain.BuildQueueItem] {
@ -69,8 +36,49 @@ func GetCounts() domain.BuildQueueCount {
return count
}
func ProcessNext() error {
func Add(buildItem domain.BuildQueueItem) error {
if strings.Contains(buildItem.BuildVersion, "+b") {
buildItem.BuildVersion = strings.Split(buildItem.BuildVersion, "+b")[0]
}
key := getQueueKey(buildItem.Source.Name, buildItem.Type)
if _, ok := queue.Get(key); ok {
return errors.New("package already in queue")
}
queue.Set(key, buildItem)
return nil
}
func Get(name string, buildType domain.BuildType) (domain.BuildQueueItem, bool) {
key := getQueueKey(name, buildType)
item, ok := queue.Get(key)
return item, ok
}
func Remove(name string, buildType domain.BuildType) error {
key := getQueueKey(name, buildType)
_, ok := queue.Get(key)
if !ok {
return errors.New("package not in queue")
}
queue.Del(key)
return nil
}
func Update(buildItem domain.BuildQueueItem) error {
key := getQueueKey(buildItem.Source.Name, buildItem.Type)
item, ok := queue.Get(key)
if !ok {
return errors.New("package not in queue")
}
if item.Status == domain.Building {
return errors.New("package is already building")
}
queue.Set(key, buildItem)
return nil
}
func ProcessNext() error {
var item *domain.BuildQueueItem
queue.ForEach(func(k string, v domain.BuildQueueItem) bool {
if v.Status == domain.Queued {
@ -82,21 +90,6 @@ func ProcessNext() error {
if item == nil {
return nil
}
if item.Source.Has32bit && domain.BuildTypeI386 != "i386" {
i386Item := domain.BuildQueueItem{
Source: item.Source,
Status: domain.Building,
Type: domain.BuildTypeI386,
Patch: item.Patch,
Rebuild: item.Rebuild,
BuildNumber: item.BuildNumber,
BuildVersion: item.BuildVersion,
}
err := UpdateBuildFile(i386Item)
if err != nil {
return err
}
}
err := UpdateBuildFile(*item)
if err != nil {

View File

@ -45,31 +45,45 @@ func processPackages() {
}
state, _ := helpers.DBInst.GetBuildState(v.Name)
if state.BuildNumber > 1 {
if state.BuildNumber > 3 {
return true
}
buildItem := createBuildItem(v, state)
if err := Add(buildItem); err != nil {
slog.Info("unable to add package to queue", "error", err)
if state.BuildNumber > 1 && state.Type == string(domain.BuildTypeI386) {
return true
}
queueBuildItem(v, state, false)
if v.Has32bit {
queueBuildItem(v, state, true)
}
return true
})
}
func shouldBuild(v domain.SourcePackage) bool {
return v.Status == domain.Missing || v.Status == domain.Stale || v.Status == domain.Error
func queueBuildItem(v domain.SourcePackage, state domain.BuildState, isI386 bool) {
buildItem := createBuildItem(v, state, isI386)
if err := Add(buildItem); err != nil {
slog.Info("unable to add package to queue", "error", err)
}
}
func createBuildItem(v domain.SourcePackage, state domain.BuildState) domain.BuildQueueItem {
func createBuildItem(v domain.SourcePackage, state domain.BuildState, isI386 bool) domain.BuildQueueItem {
buildVersion := v.NewVersion
if buildVersion == "" {
buildVersion = v.Version
}
typ := domain.BuildTypeLTO
var typ domain.BuildType
if isI386 {
typ = domain.BuildTypeI386
} else {
typ = domain.BuildTypeLTO
if state.BuildNumber == 1 {
typ = domain.BuildTypeNormal
} else if state.BuildNumber == 2 {
typ = domain.BuildTypeAmd64
}
}
return domain.BuildQueueItem{
@ -82,6 +96,9 @@ func createBuildItem(v domain.SourcePackage, state domain.BuildState) domain.Bui
BuildVersion: buildVersion,
}
}
func shouldBuild(v domain.SourcePackage) bool {
return v.Status == domain.Missing || v.Status == domain.Stale || v.Status == domain.Error
}
func processQueueAndStatus(ctx context.Context) {
for {
@ -97,7 +114,10 @@ func processQueueAndStatus(ctx context.Context) {
func processQueue() {
q := GetQueue()
itemsToRemove := []string{}
itemsToRemove := []struct {
name string
buildType domain.BuildType
}{}
buildingFound := false
q.ForEach(func(k string, item domain.BuildQueueItem) bool {
@ -106,14 +126,20 @@ func processQueue() {
complete, err := checkIfBuildComplete(item)
if complete {
handleCompletedBuild(item, err)
itemsToRemove = append(itemsToRemove, k)
itemsToRemove = append(itemsToRemove, struct {
name string
buildType domain.BuildType
}{
name: item.Source.Name,
buildType: item.Type,
})
}
}
return true
})
for _, item := range itemsToRemove {
Remove(item)
Remove(item.name, item.buildType)
}
if !buildingFound {
@ -159,10 +185,12 @@ func updateBuildState(item domain.BuildQueueItem, buildStatus domain.PackageStat
Name: item.Source.Name,
Status: string(domain.Queued),
BuildVersion: item.BuildVersion,
Type: string(item.Type),
BuildNumber: 0,
}
}
state.Status = string(buildStatus)
state.Type = string(item.Type)
state.BuildVersion = item.BuildVersion
state.BuildNumber++
helpers.DBInst.UpdateBuildState(state)

View File

@ -10,6 +10,8 @@ const (
BuildTypeLTO BuildType = "lto"
// BuildType is an i386 build
BuildTypeI386 BuildType = "i386"
// BuildType is an amd64 build
BuildTypeAmd64 BuildType = "amd64"
)
const (
@ -38,5 +40,6 @@ type BuildState struct {
Name string `gorm:"primarykey"`
Status string
BuildVersion string
Type string
BuildNumber int
}