mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-05-18 06:41:43 +02:00
feat: add job commit service
Sync jobs from job cache table to main job table. Enables #392
This commit is contained in:
parent
40110580e0
commit
d76b1ae75d
35
internal/taskManager/commitJobService.go
Normal file
35
internal/taskManager/commitJobService.go
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// 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"
|
||||||
|
"github.com/ClusterCockpit/cc-backend/internal/repository"
|
||||||
|
"github.com/ClusterCockpit/cc-backend/pkg/log"
|
||||||
|
"github.com/go-co-op/gocron/v2"
|
||||||
|
)
|
||||||
|
|
||||||
|
func RegisterCommitJobService() {
|
||||||
|
var frequency string
|
||||||
|
if config.Keys.CronFrequency != nil && config.Keys.CronFrequency.CommitJobWorker != "" {
|
||||||
|
frequency = config.Keys.CronFrequency.CommitJobWorker
|
||||||
|
} else {
|
||||||
|
frequency = "2m"
|
||||||
|
}
|
||||||
|
d, _ := time.ParseDuration(frequency)
|
||||||
|
log.Infof("Register commitJob service with %s interval", frequency)
|
||||||
|
|
||||||
|
s.NewJob(gocron.DurationJob(d),
|
||||||
|
gocron.NewTask(
|
||||||
|
func() {
|
||||||
|
start := time.Now()
|
||||||
|
log.Printf("Jobcache sync started at %s", start.Format(time.RFC3339))
|
||||||
|
jobRepo.SyncJobs()
|
||||||
|
repository.CallJobStartHooks()
|
||||||
|
log.Printf("Jobcache sync is done and took %s", time.Since(start))
|
||||||
|
}))
|
||||||
|
}
|
@ -81,6 +81,7 @@ func Start() {
|
|||||||
|
|
||||||
RegisterFootprintWorker()
|
RegisterFootprintWorker()
|
||||||
RegisterUpdateDurationWorker()
|
RegisterUpdateDurationWorker()
|
||||||
|
RegisterCommitJobService()
|
||||||
|
|
||||||
s.Start()
|
s.Start()
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,8 @@ type ResampleConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CronFrequency struct {
|
type CronFrequency struct {
|
||||||
|
// Duration Update Worker [Defaults to '2m']
|
||||||
|
CommitJobWorker string `json:"commit-job-worker"`
|
||||||
// Duration Update Worker [Defaults to '5m']
|
// Duration Update Worker [Defaults to '5m']
|
||||||
DurationWorker string `json:"duration-worker"`
|
DurationWorker string `json:"duration-worker"`
|
||||||
// Metric-Footprint Update Worker [Defaults to '10m']
|
// Metric-Footprint Update Worker [Defaults to '10m']
|
||||||
@ -150,7 +152,7 @@ type ProgramConfig struct {
|
|||||||
|
|
||||||
// If overwritten, at least all the options in the defaults below must
|
// If overwritten, at least all the options in the defaults below must
|
||||||
// be provided! Most options here can be overwritten by the user.
|
// be provided! Most options here can be overwritten by the user.
|
||||||
UiDefaults map[string]interface{} `json:"ui-defaults"`
|
UiDefaults map[string]any `json:"ui-defaults"`
|
||||||
|
|
||||||
// If exists, will enable dynamic zoom in frontend metric plots using the configured values
|
// If exists, will enable dynamic zoom in frontend metric plots using the configured values
|
||||||
EnableResampling *ResampleConfig `json:"enable-resampling"`
|
EnableResampling *ResampleConfig `json:"enable-resampling"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user