Cleanup jobschedule channel passing
This commit is contained in:
+5
-10
@@ -6,7 +6,6 @@ import (
|
||||
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||
"git.ohea.xyz/cursorius/server/pipeline_api"
|
||||
"git.ohea.xyz/cursorius/server/webhook"
|
||||
"github.com/op/go-logging"
|
||||
"golang.org/x/net/http2"
|
||||
@@ -16,13 +15,10 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
func setupHTTPServer(runCh chan jobscheduler.Run, registerCh chan jobscheduler.RunnerRegistration,
|
||||
conf config.Config) *http.ServeMux {
|
||||
func setupHTTPServer(mux *http.ServeMux, registerCh chan jobscheduler.RunnerRegistration,
|
||||
conf config.Config) {
|
||||
|
||||
mux := http.NewServeMux()
|
||||
|
||||
webhook.CreateWebhookHandler(runCh, conf, mux)
|
||||
pipeline_api.CreateHandler(mux)
|
||||
webhook.CreateWebhookHandler(conf, mux)
|
||||
mux.HandleFunc("/runner", func(w http.ResponseWriter, r *http.Request) {
|
||||
conn, err := websocket.Accept(w, r, nil)
|
||||
if err != nil {
|
||||
@@ -31,12 +27,11 @@ func setupHTTPServer(runCh chan jobscheduler.Run, registerCh chan jobscheduler.R
|
||||
}
|
||||
go jobscheduler.RegisterRunner(conn, registerCh)
|
||||
})
|
||||
return mux
|
||||
}
|
||||
|
||||
func Listen(address string, port int, runCh chan jobscheduler.Run, registerCh chan jobscheduler.RunnerRegistration, conf config.Config) {
|
||||
func Listen(mux *http.ServeMux, address string, port int, registerCh chan jobscheduler.RunnerRegistration, conf config.Config) {
|
||||
|
||||
mux := setupHTTPServer(runCh, registerCh, conf)
|
||||
setupHTTPServer(mux, registerCh, conf)
|
||||
|
||||
connect_string := fmt.Sprintf("%v:%v", address, port)
|
||||
log.Noticef("Launching HTTP server on %v\n", connect_string)
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||
"git.ohea.xyz/cursorius/server/listen"
|
||||
"git.ohea.xyz/cursorius/server/pipeline_api"
|
||||
"git.ohea.xyz/cursorius/server/poll"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
@@ -38,6 +40,9 @@ func main() {
|
||||
|
||||
poll.StartPolling(configData.Config, runCh)
|
||||
|
||||
listen.Listen(configData.Config.Address, configData.Config.Port, runCh, registerCh, configData.Config)
|
||||
mux := http.NewServeMux()
|
||||
|
||||
pipeline_api.CreateHandler(mux, runCh)
|
||||
|
||||
listen.Listen(mux, configData.Config.Address, configData.Config.Port, registerCh, configData.Config)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||
apiv1 "git.ohea.xyz/cursorius/server/proto/gen/api/v1"
|
||||
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
||||
"github.com/bufbuild/connect-go"
|
||||
@@ -12,7 +13,9 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
type ApiServer struct{}
|
||||
type ApiServer struct {
|
||||
runCh chan jobscheduler.Run
|
||||
}
|
||||
|
||||
func (s *ApiServer) GetRunner(
|
||||
ctx context.Context,
|
||||
@@ -40,8 +43,8 @@ func (s *ApiServer) RunCommand(
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func CreateHandler(mux *http.ServeMux) {
|
||||
api_server := &ApiServer{}
|
||||
func CreateHandler(mux *http.ServeMux, runCh chan jobscheduler.Run) {
|
||||
api_server := &ApiServer{runCh: runCh}
|
||||
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
||||
mux.Handle(path, handler)
|
||||
path, handler = apiv1connect.NewRunCommandServiceHandler(api_server)
|
||||
|
||||
+1
-2
@@ -5,7 +5,6 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.ohea.xyz/cursorius/server/config"
|
||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||
"git.ohea.xyz/cursorius/server/pipeline_executor"
|
||||
"github.com/go-playground/webhooks/v6/gitea"
|
||||
"github.com/op/go-logging"
|
||||
@@ -13,7 +12,7 @@ import (
|
||||
|
||||
var log = logging.MustGetLogger("cursorius-server")
|
||||
|
||||
func CreateWebhookHandler(runCh chan jobscheduler.Run, conf config.Config, mux *http.ServeMux) {
|
||||
func CreateWebhookHandler(conf config.Config, mux *http.ServeMux) {
|
||||
mux.HandleFunc("/webhook/", func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case "POST":
|
||||
|
||||
Reference in New Issue
Block a user