Changed api runner id to use a UUID

This commit is contained in:
2023-01-01 13:01:55 -07:00
parent 984321c9fc
commit 711a0257fc
5 changed files with 26 additions and 29 deletions
+6 -11
View File
@@ -11,6 +11,7 @@ import (
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
"git.ohea.xyz/cursorius/server/runnermanager"
"github.com/bufbuild/connect-go"
"github.com/google/uuid"
"github.com/op/go-logging"
)
@@ -18,9 +19,7 @@ var log = logging.MustGetLogger("cursorius-server")
type ApiServer struct {
getRunnerCh chan runnermanager.GetRunnerRequest
allocatedRunners map[int64]RunnerWrapper
currentId int64
currentIdMutex sync.Mutex
allocatedRunners map[uuid.UUID]RunnerWrapper
}
type RunnerWrapper struct {
@@ -53,15 +52,12 @@ func (s *ApiServer) GetRunner(
log.Info("Got runner with tags: %v", runnerTagsStr)
s.currentIdMutex.Lock()
runnerId := s.currentId
s.currentId++
s.currentIdMutex.Unlock()
runnerUuid := uuid.New()
s.allocatedRunners[runnerId] = RunnerWrapper{runner: response.Runner}
s.allocatedRunners[runnerUuid] = RunnerWrapper{runner: response.Runner}
res := connect.NewResponse(&apiv1.GetRunnerResponse{
RunnerId: runnerId,
Id: runnerUuid.String(),
})
res.Header().Set("GetRunner-Version", "v1")
return res, nil
@@ -84,8 +80,7 @@ func (s *ApiServer) RunCommand(
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) {
api_server := &ApiServer{
getRunnerCh: getRunnerCh,
allocatedRunners: make(map[int64]RunnerWrapper),
currentId: 0,
allocatedRunners: make(map[uuid.UUID]RunnerWrapper),
}
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
mux.Handle(path, handler)