From 6f74c8cb7705118510d0fb4bd523ea6a63282ab3 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Wed, 23 Oct 2024 16:15:44 +0200 Subject: [PATCH] feat: make cron worker frequency configurable --- internal/taskManager/updateDurationService.go | 11 +++++++++-- internal/taskManager/updateFootprintService.go | 12 ++++++++++-- pkg/schema/config.go | 10 ++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/internal/taskManager/updateDurationService.go b/internal/taskManager/updateDurationService.go index 6023547..fc7f446 100644 --- a/internal/taskManager/updateDurationService.go +++ b/internal/taskManager/updateDurationService.go @@ -7,14 +7,21 @@ package taskManager import ( "time" + "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/pkg/log" "github.com/go-co-op/gocron/v2" ) func RegisterUpdateDurationWorker() { - log.Info("Register duration update service") + var frequency string + if 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) - d, _ := time.ParseDuration("5m") s.NewJob(gocron.DurationJob(d), gocron.NewTask( func() { diff --git a/internal/taskManager/updateFootprintService.go b/internal/taskManager/updateFootprintService.go index caa4f63..a0eccc8 100644 --- a/internal/taskManager/updateFootprintService.go +++ b/internal/taskManager/updateFootprintService.go @@ -9,6 +9,7 @@ import ( "math" "time" + "github.com/ClusterCockpit/cc-backend/internal/config" "github.com/ClusterCockpit/cc-backend/internal/metricDataDispatcher" "github.com/ClusterCockpit/cc-backend/pkg/archive" "github.com/ClusterCockpit/cc-backend/pkg/log" @@ -18,8 +19,15 @@ import ( ) func RegisterFootprintWorker() { - log.Info("Register Footprint Update service") - d, _ := time.ParseDuration("10m") + var frequency string + if config.Keys.CronFrequency.FootprintWorker != "" { + frequency = config.Keys.CronFrequency.FootprintWorker + } else { + frequency = "10m" + } + d, _ := time.ParseDuration(frequency) + log.Infof("Register Footprint Update service with %s interval", frequency) + s.NewJob(gocron.DurationJob(d), gocron.NewTask( func() { diff --git a/pkg/schema/config.go b/pkg/schema/config.go index ccd848b..04e3f10 100644 --- a/pkg/schema/config.go +++ b/pkg/schema/config.go @@ -84,6 +84,13 @@ type ResampleConfig struct { Resolutions []int `json:"resolutions"` } +type CronFrequency struct { + // Duration Update Worker [Defaults to '5m'] + DurationWorker string `json:"duration-worker"` + // Metric- and Energy Footprint Update Worker [Defaults to '10m'] + FootprintWorker string `json:"footprint-worker"` +} + // Format of the configuration (file). See below for the defaults. type ProgramConfig struct { // Address where the http (or https) server will listen on (for example: 'localhost:80'). @@ -159,4 +166,7 @@ type ProgramConfig struct { // Energy Mix CO2 Emission Constant [g/kWh] // If entered, displays estimated CO2 emission for job based on jobs totalEnergy EmissionConstant int `json:"emission-constant"` + + // Frequency of cron job workers + CronFrequency *CronFrequency `json:"cron-frequency"` }