From e36124cab67238365f03a04ba6ddc3a5bc6d5ba5 Mon Sep 17 00:00:00 2001 From: ferreo Date: Tue, 30 Jul 2024 08:20:32 +0100 Subject: [PATCH] Fix error handling, only retry twice --- buildqueue/worker.go | 14 +++++++------ domain/packages.go | 1 + packages/packages.go | 49 +++++++++++++++++++++++++++++++------------- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/buildqueue/worker.go b/buildqueue/worker.go index 5ab5883..cfec8b8 100644 --- a/buildqueue/worker.go +++ b/buildqueue/worker.go @@ -30,7 +30,6 @@ func StartPackageQueueWorker(ctx context.Context) { needsBuild := false buildVersion := "" buildAttempt := 0 - errPreviously := false v.Packages.ForEach(func(k string, v domain.PackageInfo) bool { if v.Status == domain.Current { return true @@ -39,25 +38,26 @@ func StartPackageQueueWorker(ctx context.Context) { if version == "" { version = v.Version } - if v.LastBuildStatus == domain.Error { - errPreviously = true - buildAttempt = 1 - } if v.Status == domain.Missing { needsBuild = true buildVersion = version + buildAttempt = v.BuildAttempts return false } if v.Status == domain.Stale { needsBuild = true buildVersion = version + buildAttempt = v.BuildAttempts return false } return true }) if needsBuild { + if buildAttempt > 1 { + return true + } typ := domain.BuildTypeLTO - if errPreviously { + if buildAttempt == 1 { typ = domain.BuildTypeNormal } buildItem := domain.BuildQueueItem{ @@ -131,9 +131,11 @@ func processQueueAndStatus(ctx context.Context) { func updatePackageStatus(item *domain.BuildQueueItem, status domain.PackageStatus, buildStatus domain.PackageStatus) { item.Source.Packages.ForEach(func(k string, v domain.PackageInfo) bool { v.Status = status + v.BuildAttempts++ v.LastBuildStatus = domain.PackageStatus(buildStatus) if status == domain.Current { v.Version = item.BuildVersion + v.BuildAttempts = 0 v.NewVersion = "" } item.Source.Packages.Set(k, v) diff --git a/domain/packages.go b/domain/packages.go index bc82d20..0373e08 100644 --- a/domain/packages.go +++ b/domain/packages.go @@ -34,6 +34,7 @@ type PackageInfo struct { Status PackageStatus NewVersion string LastBuildStatus PackageStatus + BuildAttempts int } type PackageStatus string diff --git a/packages/packages.go b/packages/packages.go index 29f0a47..60e9a42 100644 --- a/packages/packages.go +++ b/packages/packages.go @@ -36,35 +36,56 @@ func ProcessPackages() error { return err } - // Combine packages before processing combinePackages(internalPackages) combinePackages(externalPackages) ProcessStalePackages(internalPackages, externalPackages) ProcessMissingPackages(internalPackages, externalPackages) + updatedPackages := haxmap.New[string, domain.SourcePackage]() + internalPackages.ForEach(func(k string, v domain.SourcePackage) bool { - curr, ok := currentPackagesFastMap.Get(k) - if !ok { - currentPackagesFastMap.Set(k, v) + curr, exists := currentPackagesFastMap.Get(k) + if !exists { + updatedPackages.Set(k, v) return true } - curr.Packages.ForEach(func(kk string, pk domain.PackageInfo) bool { - v.Packages.ForEach(func(vv string, pv domain.PackageInfo) bool { - if pv.PackageName == pk.PackageName { - if pk.Status == domain.Error { - pv.LastBuildStatus = domain.Error - } - curr.Packages.Set(vv, pv) + + mergedPackage := domain.SourcePackage{ + Name: curr.Name, + Packages: haxmap.New[string, domain.PackageInfo](), + } + + v.Packages.ForEach(func(pkgName string, newPkg domain.PackageInfo) bool { + if existingPkg, ok := curr.Packages.Get(pkgName); ok { + if newPkg.Version != existingPkg.Version || + newPkg.Status != existingPkg.Status || + newPkg.NewVersion != existingPkg.NewVersion { + newPkg.LastBuildStatus = domain.Error + newPkg.BuildAttempts = existingPkg.BuildAttempts + mergedPackage.Packages.Set(pkgName, newPkg) + } else { + mergedPackage.Packages.Set(pkgName, existingPkg) } - return true - }) + } else { + mergedPackage.Packages.Set(pkgName, newPkg) + } return true }) - currentPackagesFastMap.Set(k, curr) + + curr.Packages.ForEach(func(pkgName string, pkg domain.PackageInfo) bool { + if _, exists := mergedPackage.Packages.Get(pkgName); !exists { + mergedPackage.Packages.Set(pkgName, pkg) + } + return true + }) + + updatedPackages.Set(k, mergedPackage) return true }) + currentPackagesFastMap = updatedPackages + LastUpdateTime = time.Now() helpers.ReloadCache() err = SaveToDb()