fix: fixed and changed to footprint update by transactions

This commit is contained in:
Christoph Kluge
2024-10-22 14:37:22 +02:00
parent 82e28f26d7
commit 63b9e619a4
3 changed files with 40 additions and 27 deletions

View File

@@ -24,12 +24,15 @@ func RegisterFootprintWorker() {
gocron.NewTask(
func() {
s := time.Now()
log.Printf("Update Footprints started at %s using direct query execution", s.Format(time.RFC3339))
c := 0
ce := 0
cl := 0
log.Printf("Update Footprints started at %s", 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)
@@ -47,10 +50,12 @@ func RegisterFootprintWorker() {
scopes = append(scopes, schema.MetricScopeAccelerator)
for _, job := range jobs {
// log.Debugf("Try job %d", job.JobID)
log.Debugf("Try job %d", job.JobID)
cl++
jobData, err := metricDataDispatcher.LoadData(job, allMetrics, scopes, context.Background(), 0) // 0 Resolution-Value retrieves highest res
if err != nil {
log.Errorf("Error wile loading job data for footprint update: %v", err)
ce++
continue
}
@@ -65,6 +70,7 @@ func RegisterFootprintWorker() {
nodeData, ok := data["node"]
if !ok {
// This should never happen ?
ce++
continue
}
@@ -92,33 +98,38 @@ func RegisterFootprintWorker() {
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())
ce++
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())
ce++
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 footprint (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)
ce++
continue
}
// Args: JSON, JSON, ENERGY, JOBID
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
// }
c++
log.Debugf("Finish Job %d", job.JobID)
}
jobRepo.TransactionCommit(t)
log.Debugf("Finish Cluster %s", cluster.Name)
// jobRepo.TransactionCommit(t)
}
// jobRepo.TransactionEnd(t)
log.Printf("Update Footprints is done and took %s", time.Since(s))
jobRepo.TransactionEnd(t)
log.Printf("Updating %d (of %d; Skipped %d) Footprints is done and took %s", c, cl, ce, time.Since(s))
}))
}