mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-23 21:01:40 +02:00
Extend Job Hooks and add unit tests
Add job tagger control
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"bufio"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -27,16 +28,10 @@ type appInfo struct {
|
||||
}
|
||||
|
||||
type AppTagger struct {
|
||||
apps []appInfo
|
||||
apps map[string]appInfo
|
||||
}
|
||||
|
||||
func (t *AppTagger) Register() error {
|
||||
files, err := appFiles.ReadDir("apps")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading app folder: %#v", err)
|
||||
}
|
||||
t.apps = make([]appInfo, 0)
|
||||
|
||||
func (t *AppTagger) scanApps(files []fs.DirEntry) error {
|
||||
for _, fn := range files {
|
||||
fns := fn.Name()
|
||||
log.Debugf("Process: %s", fns)
|
||||
@@ -50,12 +45,25 @@ func (t *AppTagger) Register() error {
|
||||
for scanner.Scan() {
|
||||
ai.strings = append(ai.strings, scanner.Text())
|
||||
}
|
||||
t.apps = append(t.apps, ai)
|
||||
delete(t.apps, ai.tag)
|
||||
t.apps[ai.tag] = ai
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// func (t *AppTagger) Reload() error {
|
||||
//
|
||||
// }
|
||||
|
||||
func (t *AppTagger) Register() error {
|
||||
files, err := appFiles.ReadDir("apps")
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading app folder: %#v", err)
|
||||
}
|
||||
t.apps = make(map[string]appInfo, 0)
|
||||
return t.scanApps(files)
|
||||
}
|
||||
|
||||
func (t *AppTagger) Match(job *schema.Job) {
|
||||
r := repository.GetJobRepository()
|
||||
meta, err := r.FetchMetadata(job)
|
||||
|
Reference in New Issue
Block a user