From 7531ba4b5cd3dce2e7d875690e195586a8e0122b Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 27 Jun 2025 14:11:10 +0200 Subject: [PATCH] Refine app detection Switch to regexp --- internal/repository/tags.go | 4 ++-- internal/tagger/apps/qe.txt | 3 --- internal/tagger/apps/starccm.txt | 2 ++ internal/tagger/detectApp.go | 4 +++- 4 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 internal/tagger/apps/qe.txt create mode 100644 internal/tagger/apps/starccm.txt diff --git a/internal/repository/tags.go b/internal/repository/tags.go index 3a81901..18ce62f 100644 --- a/internal/repository/tags.go +++ b/internal/repository/tags.go @@ -152,13 +152,13 @@ func (r *JobRepository) removeTagFromArchiveJobs(jobIds []int64) { for _, j := range jobIds { tags, err := r.getArchiveTags(&j) if err != nil { - log.Warn("Error while getting tags for job") + log.Warnf("Error while getting tags for job %d", j) continue } job, err := r.FindByIdDirect(j) if err != nil { - log.Warn("Error while getting job") + log.Warnf("Error while getting job %d", j) continue } diff --git a/internal/tagger/apps/qe.txt b/internal/tagger/apps/qe.txt deleted file mode 100644 index a1f7106..0000000 --- a/internal/tagger/apps/qe.txt +++ /dev/null @@ -1,3 +0,0 @@ -pw -neb -ph diff --git a/internal/tagger/apps/starccm.txt b/internal/tagger/apps/starccm.txt new file mode 100644 index 0000000..97cd388 --- /dev/null +++ b/internal/tagger/apps/starccm.txt @@ -0,0 +1,2 @@ +starccm+ +-podkey diff --git a/internal/tagger/detectApp.go b/internal/tagger/detectApp.go index 6b73f56..d82db1a 100644 --- a/internal/tagger/detectApp.go +++ b/internal/tagger/detectApp.go @@ -11,6 +11,7 @@ import ( "io/fs" "os" "path/filepath" + "regexp" "strings" "github.com/ClusterCockpit/cc-backend/internal/repository" @@ -111,7 +112,8 @@ func (t *AppTagger) Match(job *schema.Job) { for _, a := range t.apps { tag := a.tag for _, s := range a.strings { - if strings.Contains(strings.ToLower(jobscript), fmt.Sprintf(" %s ", s)) { + matched, _ := regexp.MatchString(s, strings.ToLower(jobscript)) + if matched { if !r.HasTag(id, t.tagType, tag) { r.AddTagOrCreateDirect(id, t.tagType, tag) break out