Extend Job Hooks and add unit tests

Add job tagger control
This commit is contained in:
2025-05-19 13:25:39 +02:00
parent 99f8187092
commit 14bad81b9f
9 changed files with 150 additions and 31 deletions

View File

@@ -4,14 +4,48 @@
// license that can be found in the LICENSE file.
package tagger
import "github.com/ClusterCockpit/cc-backend/pkg/schema"
import (
"sync"
"github.com/ClusterCockpit/cc-backend/internal/repository"
"github.com/ClusterCockpit/cc-backend/pkg/schema"
)
type Tagger interface {
Register() error
Match(job *schema.Job)
}
func Init() error {
var (
initOnce sync.Once
jobTagger *JobTagger
)
return nil
type JobTagger struct {
startTaggers []Tagger
stopTaggers []Tagger
}
func Init() {
initOnce.Do(func() {
jobTagger = &JobTagger{}
jobTagger.startTaggers = make([]Tagger, 0)
jobTagger.startTaggers = append(jobTagger.startTaggers, &AppTagger{})
for _, tagger := range jobTagger.startTaggers {
tagger.Register()
}
// jobTagger.stopTaggers = make([]Tagger, 0)
repository.RegisterJobJook(jobTagger)
})
}
func (jt *JobTagger) JobStartCallback(job *schema.Job) {
for _, tagger := range jobTagger.startTaggers {
tagger.Match(job)
}
}
func (jt *JobTagger) JobStopCallback(job *schema.Job) {
}