Utilify runner tag printing function

This commit is contained in:
restitux 2023-03-07 23:09:49 -07:00
parent d9ba14550e
commit f190274bce
3 changed files with 25 additions and 20 deletions

View File

@ -10,6 +10,7 @@ import (
apiv2 "git.ohea.xyz/cursorius/pipeline-api/go/api/v2"
"git.ohea.xyz/cursorius/pipeline-api/go/api/v2/apiv2connect"
"git.ohea.xyz/cursorius/server/runnermanager"
"git.ohea.xyz/cursorius/server/util"
"github.com/bufbuild/connect-go"
"github.com/google/uuid"
"github.com/op/go-logging"
@ -61,22 +62,15 @@ func (s *ApiServer) GetRunner(
RespChan: respChan,
}
var runnerTagsStr strings.Builder
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, "]")
}
tagsStr := util.FormatTags(req.Msg.Tags)
response := <-respChan
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"))
}
log.Infof("Got runner with tags: %v", runnerTagsStr.String())
log.Infof("Got runner with tags: %v", tagsStr)
runnerUuid := uuid.New()

View File

@ -3,7 +3,6 @@ package runnermanager
import (
"context"
"fmt"
"strings"
"time"
"github.com/google/uuid"
@ -13,6 +12,7 @@ import (
"git.ohea.xyz/cursorius/server/config"
"git.ohea.xyz/cursorius/server/database"
"git.ohea.xyz/cursorius/server/util"
runner_api "git.ohea.xyz/cursorius/runner-api/go/api/v2"
)
@ -51,15 +51,8 @@ type runnerJob struct {
}
func (r *runnerManager) processRequest(req GetRunnerRequest) {
var runnerTagsStr strings.Builder
if len(req.Tags) > 0 {
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())
tagsStr := util.FormatTags(req.Tags)
log.Infof("Got request for runner with tags \"%v\"", tagsStr)
log.Debugf("Finding runner with tags %v", runnerTagsStr.String())

18
util/util.go Normal file
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()
}