1- package engine
1+ package http
22
33import (
44 "net/http"
55
66 "github.com/gorilla/mux"
77 "github.com/w-h-a/pkg/serverv2"
88 httpserver "github.com/w-h-a/pkg/serverv2/http"
9- "github.com/w-h-a/workflow/internal/engine/clients/broker"
10- "github.com/w-h-a/workflow/internal/engine/clients/notifier"
11- "github.com/w-h-a/workflow/internal/engine/clients/readwriter"
12- "github.com/w-h-a/workflow/internal/engine/clients/runner"
139 "github.com/w-h-a/workflow/internal/engine/config"
14- httphandlers "github.com/w-h-a/workflow/internal/engine/handlers/http"
1510 "github.com/w-h-a/workflow/internal/engine/services/coordinator"
1611 "github.com/w-h-a/workflow/internal/engine/services/streamer"
1712 "github.com/w-h-a/workflow/internal/engine/services/worker"
18- "github.com/w-h-a/workflow/internal/log"
19- "github.com/w-h-a/workflow/internal/task"
2013 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2114 "go.opentelemetry.io/otel"
2215)
2316
24- func NewCoordinator (
25- brokerClient broker.Broker ,
26- readwriterClient readwriter.ReadWriter ,
27- notifierClient notifier.Notifier ,
28- ) (serverv2.Server , * coordinator.Service ) {
29- // services
30- coordinatorService := coordinator .New (
31- brokerClient ,
32- readwriterClient ,
33- notifierClient ,
34- map [string ]int {
35- string (task .Started ): 1 ,
36- string (task .Completed ): 1 ,
37- string (task .Failed ): 1 ,
38- },
39- )
40-
17+ func NewCoordinatorServer (
18+ coordinatorService * coordinator.Service ,
19+ ) serverv2.Server {
4120 // base server options
4221 opts := []serverv2.ServerOption {
4322 serverv2 .ServerWithNamespace (config .Env ()),
@@ -48,10 +27,10 @@ func NewCoordinator(
4827 // create http router
4928 router := mux .NewRouter ()
5029
51- httpStatus := httphandlers . NewStatusHandler (coordinatorService )
30+ httpStatus := NewStatusHandler (coordinatorService )
5231 router .Methods (http .MethodGet ).Path ("/status" ).HandlerFunc (httpStatus .GetStatus )
5332
54- httpTasks := httphandlers . NewTasksHandler (coordinatorService )
33+ httpTasks := NewTasksHandler (coordinatorService )
5534 router .Methods (http .MethodGet ).Path ("/tasks" ).HandlerFunc (httpTasks .GetTasks )
5635 router .Methods (http .MethodGet ).Path ("/tasks/{id}" ).HandlerFunc (httpTasks .GetOneTask )
5736 router .Methods (http .MethodPut ).Path ("/tasks/cancel/{id}" ).HandlerFunc (httpTasks .PutCancelTask )
@@ -78,20 +57,12 @@ func NewCoordinator(
7857
7958 httpServer .Handle (handler )
8059
81- return httpServer , coordinatorService
60+ return httpServer
8261}
8362
84- func NewWorker (
85- brokerClient broker.Broker ,
86- runnerClient runner.Runner ,
87- ) (serverv2.Server , * worker.Service ) {
88- // services
89- workerService := worker .New (
90- runnerClient ,
91- brokerClient ,
92- config .WorkerQueues (),
93- )
94-
63+ func NewWorkerServer (
64+ workerService * worker.Service ,
65+ ) serverv2.Server {
9566 // base server options
9667 opts := []serverv2.ServerOption {
9768 serverv2 .ServerWithNamespace (config .Env ()),
@@ -102,7 +73,7 @@ func NewWorker(
10273 // create http router
10374 router := mux .NewRouter ()
10475
105- httpStatus := httphandlers . NewStatusHandler (workerService )
76+ httpStatus := NewStatusHandler (workerService )
10677 router .Methods (http .MethodGet ).Path ("/status" ).HandlerFunc (httpStatus .GetStatus )
10778
10879 // create http server
@@ -125,20 +96,12 @@ func NewWorker(
12596
12697 httpServer .Handle (handler )
12798
128- return httpServer , workerService
99+ return httpServer
129100}
130101
131- func NewStreamer (
132- brokerClient broker.Broker ,
133- ) (serverv2.Server , * streamer.Service ) {
134- // services
135- streamerService := streamer .New (
136- brokerClient ,
137- map [string ]int {
138- string (log .Queue ): 1 ,
139- },
140- )
141-
102+ func NewStreamerServer (
103+ streamerService * streamer.Service ,
104+ ) serverv2.Server {
142105 // base server options
143106 opts := []serverv2.ServerOption {
144107 serverv2 .ServerWithNamespace (config .Env ()),
@@ -149,10 +112,10 @@ func NewStreamer(
149112 // create http router
150113 router := mux .NewRouter ()
151114
152- httpStatus := httphandlers . NewStatusHandler (streamerService )
115+ httpStatus := NewStatusHandler (streamerService )
153116 router .Methods (http .MethodGet ).Path ("/status" ).HandlerFunc (httpStatus .GetStatus )
154117
155- httpLogs := httphandlers . NewLogsHandler (streamerService )
118+ httpLogs := NewLogsHandler (streamerService )
156119 router .Methods (http .MethodGet ).Path ("/logs/{id}" ).HandlerFunc (httpLogs .StreamLogs )
157120
158121 // create http server
@@ -175,5 +138,5 @@ func NewStreamer(
175138
176139 httpServer .Handle (handler )
177140
178- return httpServer , streamerService
141+ return httpServer
179142}
0 commit comments