From 05517fcbcd6e8da07d9c4622e16d766b5cc5441f Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Wed, 25 Sep 2024 18:04:29 +0200 Subject: [PATCH] use direct db execution for autoupdaters - transactions need to be reinvestigated --- .../taskManager/updateFootprintService.go | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/internal/taskManager/updateFootprintService.go b/internal/taskManager/updateFootprintService.go index 060e332..2a3eaef 100644 --- a/internal/taskManager/updateFootprintService.go +++ b/internal/taskManager/updateFootprintService.go @@ -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)) })) }