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

@@ -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)