Runners are removed from manager when alloacted
This removes an existing unlocked shared access to runner.running. This also sets us up for better management of the runners.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
apiv2 "git.ohea.xyz/cursorius/pipeline-api/go/api/v2"
|
||||
@@ -19,7 +18,8 @@ import (
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
type ApiServer struct {
|
||||
getRunnerCh chan runnermanager.GetRunnerRequest
|
||||
allocationCh chan runnermanager.RunnerAllocationRequest
|
||||
releaseCh chan runnermanager.RunnerReleaseRequest
|
||||
allocatedRunners map[uuid.UUID]*RunnerWrapper
|
||||
allocatedRunnersMutex sync.RWMutex
|
||||
}
|
||||
@@ -38,10 +38,14 @@ func (r *RunnerWrapper) RunCommand(cmd string, args []string) (int64, string, st
|
||||
return return_code, stdout, stderr, err
|
||||
}
|
||||
|
||||
func (r *RunnerWrapper) Release() {
|
||||
func (r *RunnerWrapper) Release(releaseCh chan runnermanager.RunnerReleaseRequest) {
|
||||
r.mutex.Lock()
|
||||
defer r.mutex.Unlock()
|
||||
r.runner.Release()
|
||||
|
||||
releaseCh <- runnermanager.RunnerReleaseRequest{
|
||||
Runner: r.runner,
|
||||
}
|
||||
r.runner = nil
|
||||
}
|
||||
|
||||
func (s *ApiServer) GetRunnerFromMap(u uuid.UUID) (*RunnerWrapper, bool) {
|
||||
@@ -56,8 +60,8 @@ func (s *ApiServer) GetRunner(
|
||||
req *connect.Request[apiv2.GetRunnerRequest],
|
||||
) (*connect.Response[apiv2.GetRunnerResponse], error) {
|
||||
|
||||
respChan := make(chan runnermanager.GetRunnerResponse)
|
||||
s.getRunnerCh <- runnermanager.GetRunnerRequest{
|
||||
respChan := make(chan runnermanager.RunnerAllocationResponse)
|
||||
s.allocationCh <- runnermanager.RunnerAllocationRequest{
|
||||
Tags: req.Msg.Tags,
|
||||
RespChan: respChan,
|
||||
}
|
||||
@@ -99,7 +103,7 @@ func (s *ApiServer) ReleaseRunner(
|
||||
s.allocatedRunnersMutex.Lock()
|
||||
runner := s.allocatedRunners[uuid]
|
||||
delete(s.allocatedRunners, uuid)
|
||||
runner.Release()
|
||||
runner.Release(s.releaseCh)
|
||||
s.allocatedRunnersMutex.Unlock()
|
||||
|
||||
res := connect.NewResponse(&apiv2.ReleaseRunnerResponse{})
|
||||
@@ -138,9 +142,10 @@ func (s *ApiServer) RunCommand(
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func CreateHandler(getRunnerCh chan runnermanager.GetRunnerRequest, mux *http.ServeMux) {
|
||||
func CreateHandler(allocationCh chan runnermanager.RunnerAllocationRequest, releaseCh chan runnermanager.RunnerReleaseRequest, mux *http.ServeMux) {
|
||||
api_server := &ApiServer{
|
||||
getRunnerCh: getRunnerCh,
|
||||
allocationCh: allocationCh,
|
||||
releaseCh: releaseCh,
|
||||
allocatedRunners: make(map[uuid.UUID]*RunnerWrapper),
|
||||
}
|
||||
path, handler := apiv2connect.NewGetRunnerServiceHandler(api_server)
|
||||
|
||||
Reference in New Issue
Block a user