added locking
This commit is contained in:
parent
e751cadbc4
commit
d1df9f6943
26
main.go
26
main.go
@ -81,6 +81,7 @@ type BuildManager struct {
|
||||
failedMutex sync.RWMutex
|
||||
buildProcesses []*os.Process
|
||||
buildProcMutex sync.RWMutex
|
||||
sqliteMutex sync.RWMutex
|
||||
}
|
||||
|
||||
type Conf struct {
|
||||
@ -300,10 +301,13 @@ func (b *BuildManager) buildWorker(id int) {
|
||||
|
||||
log.Infof("[%s/%s] Build starting", pkg.FullRepo, pkg.Pkgbase)
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
dbPkg := getDbPackage(pkg)
|
||||
b.sqliteMutex.Lock()
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
dbPkg.Status = "Building"
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
|
||||
importKeys(pkg)
|
||||
increasePkgRel(pkg)
|
||||
@ -359,12 +363,15 @@ func (b *BuildManager) buildWorker(id int) {
|
||||
check(os.MkdirAll(filepath.Join(conf.Basedir.Repo, "logs"), os.ModePerm))
|
||||
check(os.WriteFile(filepath.Join(conf.Basedir.Repo, "logs", pkg.Pkgbase+".log"), out.Bytes(), os.ModePerm))
|
||||
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
dbPkg := getDbPackage(pkg)
|
||||
b.sqliteMutex.Lock()
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
dbPkg.Status = "Failed"
|
||||
dbPkg.BuildTime = time.Now()
|
||||
dbPkg.BuildDuration = time.Now().Sub(start)
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
|
||||
gitClean(pkg)
|
||||
b.buildWG.Done()
|
||||
@ -414,12 +421,15 @@ func (b *BuildManager) buildWorker(id int) {
|
||||
check(os.Remove(filepath.Join(conf.Basedir.Repo, "logs", pkg.Pkgbase+".log")))
|
||||
}
|
||||
|
||||
db, err = gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
dbPkg = getDbPackage(pkg)
|
||||
b.sqliteMutex.Lock()
|
||||
db, err = gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
dbPkg.Status = "Build"
|
||||
dbPkg.BuildTime = time.Now()
|
||||
dbPkg.BuildDuration = time.Now().Sub(start)
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
|
||||
log.Infof("[%s/%s] Build successful (%s)", pkg.FullRepo, pkg.Pkgbase, time.Now().Sub(start))
|
||||
b.repoAdd[pkg.FullRepo] <- pkg
|
||||
@ -431,6 +441,7 @@ func (b *BuildManager) buildWorker(id int) {
|
||||
|
||||
func getDbPackage(pkg *BuildPackage) *DbPackage {
|
||||
var dbPkg DbPackage
|
||||
buildManager.sqliteMutex.Lock()
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
db.Where(DbPackage{PkgBase: pkg.Pkgbase}).Attrs(DbPackage{March: pkg.March, Packages: packages2string(pkg.Srcinfo.Packages), Repository: pkg.Repo}).FirstOrInit(&dbPkg)
|
||||
@ -441,6 +452,7 @@ func getDbPackage(pkg *BuildPackage) *DbPackage {
|
||||
} else if db.Error != nil {
|
||||
log.Panicf("Database error: %v", db.Error)
|
||||
}
|
||||
buildManager.sqliteMutex.Unlock()
|
||||
|
||||
return &dbPkg
|
||||
}
|
||||
@ -500,11 +512,14 @@ func (b *BuildManager) parseWorker() {
|
||||
skipping = true
|
||||
}
|
||||
|
||||
b.sqliteMutex.Lock()
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
|
||||
if skipping {
|
||||
b.repoPurge[pkg.FullRepo] <- pkg
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
b.parseWG.Done()
|
||||
continue
|
||||
}
|
||||
@ -516,12 +531,14 @@ func (b *BuildManager) parseWorker() {
|
||||
dbPkg.Status = "Latest"
|
||||
dbPkg.SkipReason = ""
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
b.parseWG.Done()
|
||||
continue
|
||||
}
|
||||
|
||||
dbPkg.Status = "Queued"
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
|
||||
b.build <- pkg
|
||||
}
|
||||
@ -647,8 +664,11 @@ func (b *BuildManager) repoWorker(repo string) {
|
||||
dbPkg := getDbPackage(pkg)
|
||||
dbPkg.Status = "Latest"
|
||||
dbPkg.SkipReason = ""
|
||||
b.sqliteMutex.Lock()
|
||||
db, err := gorm.Open(sqlite.Open(conf.Basedir.Db), &gorm.Config{})
|
||||
check(err)
|
||||
db.Save(dbPkg)
|
||||
b.sqliteMutex.Unlock()
|
||||
|
||||
cmd = exec.Command("paccache",
|
||||
"-rc", filepath.Join(conf.Basedir.Repo, pkg.FullRepo, "os", conf.Arch),
|
||||
|
Loading…
Reference in New Issue
Block a user