diff --git a/buildqueue/worker.go b/buildqueue/worker.go index 22fbe9b..ffa3132 100644 --- a/buildqueue/worker.go +++ b/buildqueue/worker.go @@ -13,7 +13,6 @@ import ( "time" "golang.org/x/net/html" - "pault.ag/go/debian/version" ) func StartPackageQueueWorker(ctx context.Context) { @@ -29,37 +28,11 @@ func StartPackageQueueWorker(ctx context.Context) { } packs := packages.GetPackages() packs.ForEach(func(k string, v domain.SourcePackage) bool { - needsBuild := false - buildVersion := "" - v.Packages.ForEach(func(k string, v domain.PackageInfo) bool { - if v.Status == domain.Current { - return true - } - vs := v.NewVersion - if vs == "" { - vs = v.Version - } - if v.Status == domain.Missing || v.Status == domain.Stale { - needsBuild = true - } - if buildVersion == "" { - buildVersion = vs - } else { - ver, err := version.Parse(buildVersion) - if err != nil { - return true - } - vsVer, err := version.Parse(vs) - if err != nil { - return true - } - if version.Compare(ver, vsVer) < 0 { - buildVersion = vs - } - } - - return true - }) + needsBuild := v.Status == domain.Missing || v.Status == domain.Stale || v.Status == domain.Error + buildVersion := v.NewVersion + if buildVersion == "" { + buildVersion = v.Version + } if needsBuild { state, err := helpers.DBInst.GetBuildState(v.Name) if err != nil { @@ -117,9 +90,16 @@ func processQueueAndStatus(ctx context.Context) { if err != nil { updateBuildState(item, domain.Error) + item.Source.Status = domain.Error + item.Source.LastBuildStatus = domain.Error + item.Source.BuildAttempts++ updatePackageStatus(&item, domain.Error) } else { updateBuildState(item, domain.Built) + item.Source.Status = domain.Built + item.Source.LastBuildStatus = domain.Built + item.Source.BuildAttempts = 0 + item.Source.Version = item.BuildVersion updatePackageStatus(&item, domain.Current) } packages.UpdateSourcePackage(item.Source) diff --git a/domain/packages.go b/domain/packages.go index 84a698c..e520f4f 100644 --- a/domain/packages.go +++ b/domain/packages.go @@ -16,9 +16,14 @@ type PackagesCount struct { } type SourcePackage struct { - Name string `gorm:"primarykey"` - Has32bit bool - Packages *haxmap.Map[string, PackageInfo] `gorm:"foreignKey:PackageInfo;references:PackageName"` + Name string `gorm:"primarykey"` + Has32bit bool + Version string + NewVersion string + Status PackageStatus + LastBuildStatus PackageStatus + BuildAttempts int + Packages *haxmap.Map[string, PackageInfo] `gorm:"foreignKey:PackageInfo;references:PackageName"` } type SourcePackageDTO struct { diff --git a/packages/packages.go b/packages/packages.go index 3ef4720..e701db1 100644 --- a/packages/packages.go +++ b/packages/packages.go @@ -232,6 +232,8 @@ func LoadInternalPackages(internalPackages *haxmap.Map[string, domain.SourcePack internalPackages.Set(newPkg.Source, domain.SourcePackage{ Name: newPkg.Source, Packages: newMap, + Status: domain.Current, + Version: newPkg.Version, }) return true } @@ -244,7 +246,9 @@ func LoadInternalPackages(internalPackages *haxmap.Map[string, domain.SourcePack extVer, _ := version.Parse(newPkg.Version) cmpVal := version.Compare(extVer, mVer) if cmpVal >= 0 { + pk.Version = getHighestVer(pkg.Version, newPkg.Version) pk.Packages.Set(newKey, newPkg) + internalPackages.Set(newPkg.Source, pk) return true } return true @@ -309,24 +313,41 @@ func ProcessMissingPackages(internalPackages *haxmap.Map[string, domain.SourcePa _, ok := internalPackages.Get(k) if !ok && src.Packages.Len() > 0 { newStatus := domain.Missing + vers := "" + src.Packages.ForEach(func(k string, v domain.PackageInfo) bool { v.Status = newStatus v.Version = strings.Split(v.Version, "+b")[0] + vers = getHighestVer(vers, v.Version) src.Packages.Set(k, v) return true }) + src.Version = vers + src.Status = newStatus internalPackages.Set(k, src) } return true }) } +func getHighestVer(ver string, newVer string) string { + mVer, _ := version.Parse(ver) + extVer, _ := version.Parse(newVer) + cmpVal := version.Compare(mVer, extVer) + if cmpVal < 0 { + return newVer + } + return ver +} + func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePackage], externalPackages *haxmap.Map[string, domain.SourcePackage]) { externalPackages.ForEach(func(newPackage string, newSource domain.SourcePackage) bool { matchedPackage, ok := internalPackages.Get(newPackage) if !ok || matchedPackage.Packages.Len() == 0 { return true } + ver := "" + status := matchedPackage.Status matchedPackage.Packages.ForEach(func(currentKey string, currentPackage domain.PackageInfo) bool { if currentPackage.Status == domain.Missing { return true @@ -340,9 +361,9 @@ func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePack extVer, _ := version.Parse(newVersion) cmpVal := version.Compare(mVer, extVer) if cmpVal < 0 { - if currentPackage.Status != domain.Error { - currentPackage.Status = domain.Stale - } + currentPackage.Status = domain.Stale + status = domain.Stale + ver = getHighestVer(currentPackage.Version, extVer.String()) currentPackage.NewVersion = extVer.String() matchedPackage.Packages.Set(currentKey, currentPackage) } @@ -350,6 +371,11 @@ func ProcessStalePackages(internalPackages *haxmap.Map[string, domain.SourcePack }) return true }) + if ver != matchedPackage.Version { + matchedPackage.NewVersion = ver + } + matchedPackage.Status = status + internalPackages.Set(newPackage, matchedPackage) return true }) }