Utilify runner tag printing function

This commit is contained in:
2023-03-07 23:09:49 -07:00
parent d9ba14550e
commit f190274bce
3 changed files with 25 additions and 20 deletions
+4 -10
View File
@@ -10,6 +10,7 @@ import (
apiv2 "git.ohea.xyz/cursorius/pipeline-api/go/api/v2" apiv2 "git.ohea.xyz/cursorius/pipeline-api/go/api/v2"
"git.ohea.xyz/cursorius/pipeline-api/go/api/v2/apiv2connect" "git.ohea.xyz/cursorius/pipeline-api/go/api/v2/apiv2connect"
"git.ohea.xyz/cursorius/server/runnermanager" "git.ohea.xyz/cursorius/server/runnermanager"
"git.ohea.xyz/cursorius/server/util"
"github.com/bufbuild/connect-go" "github.com/bufbuild/connect-go"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/op/go-logging" "github.com/op/go-logging"
@@ -61,22 +62,15 @@ func (s *ApiServer) GetRunner(
RespChan: respChan, RespChan: respChan,
} }
var runnerTagsStr strings.Builder tagsStr := util.FormatTags(req.Msg.Tags)
if len(req.Msg.Tags) > 0 {
fmt.Fprintf(&runnerTagsStr, "[%v", req.Msg.Tags[0])
for _, tag := range req.Msg.Tags[1:] {
fmt.Fprintf(&runnerTagsStr, ", %v", tag)
}
fmt.Fprintf(&runnerTagsStr, "]")
}
response := <-respChan response := <-respChan
if response.Err != nil { if response.Err != nil {
log.Errorf("Could not get runner with tags \"%v\": %v", runnerTagsStr.String(), response.Err) log.Errorf("Could not get runner with tags \"%v\": %v", tagsStr, response.Err)
return nil, connect.NewError(connect.CodeNotFound, fmt.Errorf("Could not get runner")) return nil, connect.NewError(connect.CodeNotFound, fmt.Errorf("Could not get runner"))
} }
log.Infof("Got runner with tags: %v", runnerTagsStr.String()) log.Infof("Got runner with tags: %v", tagsStr)
runnerUuid := uuid.New() runnerUuid := uuid.New()
+3 -10
View File
@@ -3,7 +3,6 @@ package runnermanager
import ( import (
"context" "context"
"fmt" "fmt"
"strings"
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
@@ -13,6 +12,7 @@ import (
"git.ohea.xyz/cursorius/server/config" "git.ohea.xyz/cursorius/server/config"
"git.ohea.xyz/cursorius/server/database" "git.ohea.xyz/cursorius/server/database"
"git.ohea.xyz/cursorius/server/util"
runner_api "git.ohea.xyz/cursorius/runner-api/go/api/v2" runner_api "git.ohea.xyz/cursorius/runner-api/go/api/v2"
) )
@@ -51,15 +51,8 @@ type runnerJob struct {
} }
func (r *runnerManager) processRequest(req GetRunnerRequest) { func (r *runnerManager) processRequest(req GetRunnerRequest) {
var runnerTagsStr strings.Builder tagsStr := util.FormatTags(req.Tags)
if len(req.Tags) > 0 { log.Infof("Got request for runner with tags \"%v\"", tagsStr)
fmt.Fprintf(&runnerTagsStr, "[%v", req.Tags[0])
for _, tag := range req.Tags[1:] {
fmt.Fprintf(&runnerTagsStr, ", %v", tag)
}
fmt.Fprintf(&runnerTagsStr, "]")
}
log.Infof("Got request for runner with tags \"%v\"", runnerTagsStr.String())
log.Debugf("Finding runner with tags %v", runnerTagsStr.String()) log.Debugf("Finding runner with tags %v", runnerTagsStr.String())
+18
View File
@@ -0,0 +1,18 @@
package util
import (
"fmt"
"strings"
)
func FormatTags(tags []string) string {
var tagsStr strings.Builder
if len(tags) > 0 {
fmt.Fprintf(&tagsStr, "[%v", tags[0])
for _, tag := range tags[1:] {
fmt.Fprintf(&tagsStr, ", %v", tag)
}
fmt.Fprintf(&tagsStr, "]")
}
return tagsStr.String()
}