use direct db execution for autoupdaters

- transactions need to be reinvestigated
This commit is contained in:
Christoph Kluge 2024-09-25 18:04:29 +02:00
parent 18af51b0a4
commit 05517fcbcd

View File

@ -24,12 +24,12 @@ func RegisterFootprintWorker() {
gocron.NewTask(
func() {
s := time.Now()
log.Printf("Update Footprints started at %s", s.Format(time.RFC3339))
log.Printf("Update Footprints started at %s using direct query execution", s.Format(time.RFC3339))
t, err := jobRepo.TransactionInit()
if err != nil {
log.Errorf("Failed TransactionInit %v", err)
}
// t, err := jobRepo.TransactionInit()
// if err != nil {
// log.Errorf("Failed TransactionInit %v", err)
// }
for _, cluster := range archive.Clusters {
jobs, err := jobRepo.FindRunningJobs(cluster.Name)
@ -85,35 +85,39 @@ func RegisterFootprintWorker() {
}
}
stmt := sq.Update("job").Where("job.id = ?", job.ID)
// Init UpdateBuilder
stmt := sq.Update("job")
// Add SET queries
stmt, err = jobRepo.UpdateFootprint(stmt, jobMeta)
if err != nil {
log.Errorf("Update job (dbid: %d) failed at update Footprint step: %s", job.ID, err.Error())
continue
}
stmt, err = jobRepo.UpdateEnergy(stmt, jobMeta)
if err != nil {
log.Errorf("Update job (dbid: %d) failed at update Energy step: %s", job.ID, err.Error())
continue
}
// Add WHERE Filter
stmt = stmt.Where("job.id = ?", job.ID)
query, args, err := stmt.ToSql()
if err != nil {
log.Errorf("Failed in ToSQL conversion %v", err)
continue
}
jobRepo.TransactionAdd(t, query, args)
// if err := jobRepo.Execute(stmt); err != nil {
// log.Errorf("Update job (dbid: %d) failed at db execute: %s", job.ID, err.Error())
// query, args, err := stmt.ToSql()
// if err != nil {
// log.Errorf("Failed in ToSQL conversion: %v", err)
// continue
// }
log.Debugf("Finish job %d", job.JobID)
}
jobRepo.TransactionCommit(t)
// jobRepo.TransactionAdd(t, query, args)
if err := jobRepo.Execute(stmt); err != nil {
log.Errorf("Update job footprint (dbid: %d) failed at db execute: %s", job.ID, err.Error())
continue
}
log.Debugf("Finish Job %d", job.JobID)
}
log.Debugf("Finish Cluster %s", cluster.Name)
// jobRepo.TransactionCommit(t)
}
jobRepo.TransactionEnd(t)
// jobRepo.TransactionEnd(t)
log.Printf("Update Footprints is done and took %s", time.Since(s))
}))
}