Fix broken i386 queue
This commit is contained in:
parent
b766d5ef80
commit
8e8ed73381
@ -2,6 +2,7 @@ package buildqueue
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"brunel/domain"
|
"brunel/domain"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"errors"
|
"errors"
|
||||||
@ -11,42 +12,8 @@ import (
|
|||||||
|
|
||||||
var queue = haxmap.New[string, domain.BuildQueueItem]()
|
var queue = haxmap.New[string, domain.BuildQueueItem]()
|
||||||
|
|
||||||
func Add(buildItem domain.BuildQueueItem) error {
|
func getQueueKey(name string, buildType domain.BuildType) string {
|
||||||
if strings.Contains(buildItem.BuildVersion, "+b") {
|
return fmt.Sprintf("%s_%s", name, buildType)
|
||||||
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 GetQueue() *haxmap.Map[string, domain.BuildQueueItem] {
|
func GetQueue() *haxmap.Map[string, domain.BuildQueueItem] {
|
||||||
@ -69,8 +36,49 @@ func GetCounts() domain.BuildQueueCount {
|
|||||||
return count
|
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
|
var item *domain.BuildQueueItem
|
||||||
queue.ForEach(func(k string, v domain.BuildQueueItem) bool {
|
queue.ForEach(func(k string, v domain.BuildQueueItem) bool {
|
||||||
if v.Status == domain.Queued {
|
if v.Status == domain.Queued {
|
||||||
@ -82,21 +90,6 @@ func ProcessNext() error {
|
|||||||
if item == nil {
|
if item == nil {
|
||||||
return 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)
|
err := UpdateBuildFile(*item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,31 +45,45 @@ func processPackages() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
state, _ := helpers.DBInst.GetBuildState(v.Name)
|
state, _ := helpers.DBInst.GetBuildState(v.Name)
|
||||||
if state.BuildNumber > 1 {
|
if state.BuildNumber > 3 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
buildItem := createBuildItem(v, state)
|
if state.BuildNumber > 1 && state.Type == string(domain.BuildTypeI386) {
|
||||||
if err := Add(buildItem); err != nil {
|
return true
|
||||||
slog.Info("unable to add package to queue", "error", err)
|
}
|
||||||
|
|
||||||
|
queueBuildItem(v, state, false)
|
||||||
|
if v.Has32bit {
|
||||||
|
queueBuildItem(v, state, true)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldBuild(v domain.SourcePackage) bool {
|
func queueBuildItem(v domain.SourcePackage, state domain.BuildState, isI386 bool) {
|
||||||
return v.Status == domain.Missing || v.Status == domain.Stale || v.Status == domain.Error
|
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
|
buildVersion := v.NewVersion
|
||||||
if buildVersion == "" {
|
if buildVersion == "" {
|
||||||
buildVersion = v.Version
|
buildVersion = v.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
typ := domain.BuildTypeLTO
|
var typ domain.BuildType
|
||||||
if state.BuildNumber == 1 {
|
if isI386 {
|
||||||
typ = domain.BuildTypeNormal
|
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{
|
return domain.BuildQueueItem{
|
||||||
@ -82,6 +96,9 @@ func createBuildItem(v domain.SourcePackage, state domain.BuildState) domain.Bui
|
|||||||
BuildVersion: buildVersion,
|
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) {
|
func processQueueAndStatus(ctx context.Context) {
|
||||||
for {
|
for {
|
||||||
@ -97,7 +114,10 @@ func processQueueAndStatus(ctx context.Context) {
|
|||||||
|
|
||||||
func processQueue() {
|
func processQueue() {
|
||||||
q := GetQueue()
|
q := GetQueue()
|
||||||
itemsToRemove := []string{}
|
itemsToRemove := []struct {
|
||||||
|
name string
|
||||||
|
buildType domain.BuildType
|
||||||
|
}{}
|
||||||
buildingFound := false
|
buildingFound := false
|
||||||
|
|
||||||
q.ForEach(func(k string, item domain.BuildQueueItem) bool {
|
q.ForEach(func(k string, item domain.BuildQueueItem) bool {
|
||||||
@ -106,14 +126,20 @@ func processQueue() {
|
|||||||
complete, err := checkIfBuildComplete(item)
|
complete, err := checkIfBuildComplete(item)
|
||||||
if complete {
|
if complete {
|
||||||
handleCompletedBuild(item, err)
|
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
|
return true
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, item := range itemsToRemove {
|
for _, item := range itemsToRemove {
|
||||||
Remove(item)
|
Remove(item.name, item.buildType)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !buildingFound {
|
if !buildingFound {
|
||||||
@ -159,10 +185,12 @@ func updateBuildState(item domain.BuildQueueItem, buildStatus domain.PackageStat
|
|||||||
Name: item.Source.Name,
|
Name: item.Source.Name,
|
||||||
Status: string(domain.Queued),
|
Status: string(domain.Queued),
|
||||||
BuildVersion: item.BuildVersion,
|
BuildVersion: item.BuildVersion,
|
||||||
|
Type: string(item.Type),
|
||||||
BuildNumber: 0,
|
BuildNumber: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.Status = string(buildStatus)
|
state.Status = string(buildStatus)
|
||||||
|
state.Type = string(item.Type)
|
||||||
state.BuildVersion = item.BuildVersion
|
state.BuildVersion = item.BuildVersion
|
||||||
state.BuildNumber++
|
state.BuildNumber++
|
||||||
helpers.DBInst.UpdateBuildState(state)
|
helpers.DBInst.UpdateBuildState(state)
|
||||||
|
@ -10,6 +10,8 @@ const (
|
|||||||
BuildTypeLTO BuildType = "lto"
|
BuildTypeLTO BuildType = "lto"
|
||||||
// BuildType is an i386 build
|
// BuildType is an i386 build
|
||||||
BuildTypeI386 BuildType = "i386"
|
BuildTypeI386 BuildType = "i386"
|
||||||
|
// BuildType is an amd64 build
|
||||||
|
BuildTypeAmd64 BuildType = "amd64"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -38,5 +40,6 @@ type BuildState struct {
|
|||||||
Name string `gorm:"primarykey"`
|
Name string `gorm:"primarykey"`
|
||||||
Status string
|
Status string
|
||||||
BuildVersion string
|
BuildVersion string
|
||||||
|
Type string
|
||||||
BuildNumber int
|
BuildNumber int
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user