Refactor pipeline api lister to inside listen
This commit is contained in:
+24
-4
@@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"git.ohea.xyz/cursorius/server/pipeline_api"
|
||||
"git.ohea.xyz/cursorius/server/runnermanager"
|
||||
"git.ohea.xyz/cursorius/server/webhook"
|
||||
"github.com/op/go-logging"
|
||||
@@ -15,10 +16,17 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
func setupHTTPServer(mux *http.ServeMux, registerCh chan runnermanager.RunnerRegistration,
|
||||
conf config.Config) {
|
||||
func setupHTTPServer(
|
||||
mux *http.ServeMux,
|
||||
conf config.Config,
|
||||
registerCh chan runnermanager.RunnerRegistration,
|
||||
getRunnerCh chan runnermanager.GetRunnerRequest,
|
||||
) {
|
||||
|
||||
webhook.CreateWebhookHandler(conf, mux)
|
||||
|
||||
pipeline_api.CreateHandler(getRunnerCh, mux)
|
||||
|
||||
mux.HandleFunc("/runner", func(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := websocket.Accept(w, r, 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)
|
||||
log.Noticef("Launching HTTP server on %v\n", connect_string)
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"git.ohea.xyz/cursorius/server/database"
|
||||
"git.ohea.xyz/cursorius/server/listen"
|
||||
"git.ohea.xyz/cursorius/server/pipeline_api"
|
||||
"git.ohea.xyz/cursorius/server/poll"
|
||||
"git.ohea.xyz/cursorius/server/runnermanager"
|
||||
"github.com/op/go-logging"
|
||||
@@ -51,7 +50,12 @@ func main() {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
pipeline_api.CreateHandler(mux, getRunnerCh)
|
||||
|
||||
listen.Listen(mux, configData.Config.Address, configData.Config.Port, registerCh, configData.Config)
|
||||
listen.Listen(
|
||||
mux,
|
||||
configData.Config.Address,
|
||||
configData.Config.Port,
|
||||
configData.Config,
|
||||
registerCh,
|
||||
getRunnerCh,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (s *ApiServer) RunCommand(
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func CreateHandler(mux *http.ServeMux, getRunnerCh chan runnermanager.GetRunnerRequest) {
|
||||
func CreateHandler(getRunnerCh chan runnermanager.GetRunnerRequest, mux *http.ServeMux) {
|
||||
api_server := &ApiServer{
|
||||
getRunnerCh: getRunnerCh,
|
||||
allocatedRunners: make(map[uuid.UUID]*RunnerWrapper),
|
||||
|
||||
Reference in New Issue
Block a user