Refactored runner map wrap and add to function

This commit is contained in:
2023-04-07 19:52:37 -06:00
parent bbf96498aa
commit bcc53dfbe0
+7 -3
View File
@@ -56,6 +56,12 @@ func (s *ApiServer) GetRunnerFromMap(u uuid.UUID) (*RunnerWrapper, bool) {
return runner, ok return runner, ok
} }
func (s *ApiServer) AddRunnerToMap(u uuid.UUID, runner *runnermanager.Runner) {
s.allocatedRunnersMutex.Lock()
defer s.allocatedRunnersMutex.Unlock()
s.allocatedRunners[u] = &RunnerWrapper{runner: runner}
}
func (s *ApiServer) GetRunner( func (s *ApiServer) GetRunner(
ctx context.Context, ctx context.Context,
req *connect.Request[apiv2.GetRunnerRequest], req *connect.Request[apiv2.GetRunnerRequest],
@@ -114,9 +120,7 @@ func (s *ApiServer) GetRunner(
runnerUuid := uuid.New() runnerUuid := uuid.New()
s.allocatedRunnersMutex.Lock() s.AddRunnerToMap(runnerUuid, response.Runner)
s.allocatedRunners[runnerUuid] = &RunnerWrapper{runner: response.Runner}
s.allocatedRunnersMutex.Unlock()
res := connect.NewResponse(&apiv2.GetRunnerResponse{ res := connect.NewResponse(&apiv2.GetRunnerResponse{
Id: runnerUuid.String(), Id: runnerUuid.String(),