Skip to content

Commit

Permalink
feat: make cron worker frequency configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
spacehamster87 committed Oct 23, 2024
1 parent 63b9e61 commit 6f74c8c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 9 additions & 2 deletions internal/taskManager/updateDurationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
12 changes: 10 additions & 2 deletions internal/taskManager/updateFootprintService.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/schema/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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').
Expand Down Expand Up @@ -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"`
}

0 comments on commit 6f74c8c

Please sign in to comment.