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/config"
|
||||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||||
"git.ohea.xyz/cursorius/server/pipeline_api"
|
|
||||||
"git.ohea.xyz/cursorius/server/webhook"
|
"git.ohea.xyz/cursorius/server/webhook"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
"golang.org/x/net/http2"
|
"golang.org/x/net/http2"
|
||||||
@@ -16,13 +15,10 @@ import (
|
|||||||
|
|
||||||
var log = logging.MustGetLogger("cursorius-server")
|
var log = logging.MustGetLogger("cursorius-server")
|
||||||
|
|
||||||
func setupHTTPServer(runCh chan jobscheduler.Run, registerCh chan jobscheduler.RunnerRegistration,
|
func setupHTTPServer(mux *http.ServeMux, registerCh chan jobscheduler.RunnerRegistration,
|
||||||
conf config.Config) *http.ServeMux {
|
conf config.Config) {
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
webhook.CreateWebhookHandler(conf, mux)
|
||||||
|
|
||||||
webhook.CreateWebhookHandler(runCh, conf, mux)
|
|
||||||
pipeline_api.CreateHandler(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 {
|
||||||
@@ -31,12 +27,11 @@ func setupHTTPServer(runCh chan jobscheduler.Run, registerCh chan jobscheduler.R
|
|||||||
}
|
}
|
||||||
go jobscheduler.RegisterRunner(conn, registerCh)
|
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)
|
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)
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.ohea.xyz/cursorius/server/config"
|
"git.ohea.xyz/cursorius/server/config"
|
||||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||||
"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"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
)
|
)
|
||||||
@@ -38,6 +40,9 @@ func main() {
|
|||||||
|
|
||||||
poll.StartPolling(configData.Config, runCh)
|
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"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"git.ohea.xyz/cursorius/server/jobscheduler"
|
||||||
apiv1 "git.ohea.xyz/cursorius/server/proto/gen/api/v1"
|
apiv1 "git.ohea.xyz/cursorius/server/proto/gen/api/v1"
|
||||||
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
||||||
"github.com/bufbuild/connect-go"
|
"github.com/bufbuild/connect-go"
|
||||||
@@ -12,7 +13,9 @@ import (
|
|||||||
|
|
||||||
var log = logging.MustGetLogger("cursorius-server")
|
var log = logging.MustGetLogger("cursorius-server")
|
||||||
|
|
||||||
type ApiServer struct{}
|
type ApiServer struct {
|
||||||
|
runCh chan jobscheduler.Run
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ApiServer) GetRunner(
|
func (s *ApiServer) GetRunner(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
@@ -40,8 +43,8 @@ func (s *ApiServer) RunCommand(
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateHandler(mux *http.ServeMux) {
|
func CreateHandler(mux *http.ServeMux, runCh chan jobscheduler.Run) {
|
||||||
api_server := &ApiServer{}
|
api_server := &ApiServer{runCh: runCh}
|
||||||
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
||||||
mux.Handle(path, handler)
|
mux.Handle(path, handler)
|
||||||
path, handler = apiv1connect.NewRunCommandServiceHandler(api_server)
|
path, handler = apiv1connect.NewRunCommandServiceHandler(api_server)
|
||||||
|
|||||||
+1
-2
@@ -5,7 +5,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.ohea.xyz/cursorius/server/config"
|
"git.ohea.xyz/cursorius/server/config"
|
||||||
"git.ohea.xyz/cursorius/server/jobscheduler"
|
|
||||||
"git.ohea.xyz/cursorius/server/pipeline_executor"
|
"git.ohea.xyz/cursorius/server/pipeline_executor"
|
||||||
"github.com/go-playground/webhooks/v6/gitea"
|
"github.com/go-playground/webhooks/v6/gitea"
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
@@ -13,7 +12,7 @@ import (
|
|||||||
|
|
||||||
var log = logging.MustGetLogger("cursorius-server")
|
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) {
|
mux.HandleFunc("/webhook/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "POST":
|
case "POST":
|
||||||
|
|||||||
Reference in New Issue
Block a user