cc-backend/internal/taskManager/updateDurationService.go

34 lines
989 B
Go
Raw Permalink Normal View History

2024-09-03 10:03:38 +02:00
// Copyright (C) NHR@FAU, University Erlangen-Nuremberg.
// All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package taskManager
import (
"time"
"github.com/ClusterCockpit/cc-backend/internal/config"
2024-09-03 10:03:38 +02:00
"github.com/ClusterCockpit/cc-backend/pkg/log"
"github.com/go-co-op/gocron/v2"
)
func RegisterUpdateDurationWorker() {
var frequency string
2024-10-28 11:56:34 +01:00
if config.Keys.CronFrequency != nil && config.Keys.CronFrequency.DurationWorker != "" {
frequency = config.Keys.CronFrequency.DurationWorker
} else {
frequency = "5m"
}
d, _ := time.ParseDuration(frequency)
log.Infof("Register Duration Update service with %s interval", frequency)
2024-09-03 10:03:38 +02:00
s.NewJob(gocron.DurationJob(d),
gocron.NewTask(
func() {
start := time.Now()
log.Printf("Update duration started at %s", start.Format(time.RFC3339))
jobRepo.UpdateDuration()
2024-09-03 13:41:00 +02:00
log.Printf("Update duration is done and took %s", time.Since(start))
2024-09-03 10:03:38 +02:00
}))
}