Refactor pipeline api lister to inside listen

This commit is contained in:
2023-01-14 01:35:29 -07:00
parent b58b1ab5d9
commit 30fed27126
3 changed files with 33 additions and 9 deletions
+24 -4
View File
@@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"git.ohea.xyz/cursorius/server/config" "git.ohea.xyz/cursorius/server/config"
"git.ohea.xyz/cursorius/server/pipeline_api"
"git.ohea.xyz/cursorius/server/runnermanager" "git.ohea.xyz/cursorius/server/runnermanager"
"git.ohea.xyz/cursorius/server/webhook" "git.ohea.xyz/cursorius/server/webhook"
"github.com/op/go-logging" "github.com/op/go-logging"
@@ -15,10 +16,17 @@ import (
var log = logging.MustGetLogger("cursorius-server") var log = logging.MustGetLogger("cursorius-server")
func setupHTTPServer(mux *http.ServeMux, registerCh chan runnermanager.RunnerRegistration, func setupHTTPServer(
conf config.Config) { mux *http.ServeMux,
conf config.Config,
registerCh chan runnermanager.RunnerRegistration,
getRunnerCh chan runnermanager.GetRunnerRequest,
) {
webhook.CreateWebhookHandler(conf, mux) webhook.CreateWebhookHandler(conf, mux)
pipeline_api.CreateHandler(getRunnerCh, mux)
mux.HandleFunc("/runner", func(w http.ResponseWriter, r *http.Request) { mux.HandleFunc("/runner", func(w http.ResponseWriter, r *http.Request) {
conn, err := websocket.Accept(w, r, nil) conn, err := websocket.Accept(w, r, nil)
if err != nil { if err != nil {
@@ -29,9 +37,21 @@ func setupHTTPServer(mux *http.ServeMux, registerCh chan runnermanager.RunnerReg
}) })
} }
func Listen(mux *http.ServeMux, address string, port int, registerCh chan runnermanager.RunnerRegistration, conf config.Config) { func Listen(
mux *http.ServeMux,
address string,
port int,
conf config.Config,
registerCh chan runnermanager.RunnerRegistration,
getRunnerCh chan runnermanager.GetRunnerRequest,
) {
setupHTTPServer(mux, registerCh, conf) setupHTTPServer(
mux,
conf,
registerCh,
getRunnerCh,
)
connect_string := fmt.Sprintf("%v:%v", address, port) connect_string := fmt.Sprintf("%v:%v", address, port)
log.Noticef("Launching HTTP server on %v\n", connect_string) log.Noticef("Launching HTTP server on %v\n", connect_string)
+8 -4
View File
@@ -7,7 +7,6 @@ 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/listen" "git.ohea.xyz/cursorius/server/listen"
"git.ohea.xyz/cursorius/server/pipeline_api"
"git.ohea.xyz/cursorius/server/poll" "git.ohea.xyz/cursorius/server/poll"
"git.ohea.xyz/cursorius/server/runnermanager" "git.ohea.xyz/cursorius/server/runnermanager"
"github.com/op/go-logging" "github.com/op/go-logging"
@@ -51,7 +50,12 @@ func main() {
mux := http.NewServeMux() mux := http.NewServeMux()
pipeline_api.CreateHandler(mux, getRunnerCh) listen.Listen(
mux,
listen.Listen(mux, configData.Config.Address, configData.Config.Port, registerCh, configData.Config) configData.Config.Address,
configData.Config.Port,
configData.Config,
registerCh,
getRunnerCh,
)
} }
+1 -1
View File
@@ -144,7 +144,7 @@ func (s *ApiServer) RunCommand(
return res, nil return res, nil
} }
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) { func CreateHandler(getRunnerCh chan runnermanager.GetRunnerRequest, mux *http.ServeMux) {
api_server := &ApiServer{ api_server := &ApiServer{
getRunnerCh: getRunnerCh, getRunnerCh: getRunnerCh,
allocatedRunners: make(map[uuid.UUID]*RunnerWrapper), allocatedRunners: make(map[uuid.UUID]*RunnerWrapper),