mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-28 05:45:30 +00:00
change to start/stop not run/stop
This commit is contained in:
@@ -177,7 +177,7 @@ func run(ctx context.Context, c *cli.Command) error {
|
|||||||
routerRunner := sync.WaitGroup{}
|
routerRunner := sync.WaitGroup{}
|
||||||
|
|
||||||
routerRunner.Go(func() {
|
routerRunner.Go(func() {
|
||||||
router.Run(context.Background())
|
router.Start(context.Background())
|
||||||
})
|
})
|
||||||
|
|
||||||
<-ctx.Done()
|
<-ctx.Done()
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (hc *HTTPClient) Type() string {
|
|||||||
return hc.config.Type
|
return hc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hc *HTTPClient) Run(ctx context.Context) error {
|
func (hc *HTTPClient) Start(ctx context.Context) error {
|
||||||
hc.logger.Debug("running")
|
hc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ func (hs *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (hs *HTTPServer) Run(ctx context.Context) error {
|
func (hs *HTTPServer) Start(ctx context.Context) error {
|
||||||
hs.logger.Debug("running")
|
hs.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func (mi *MIDIInput) Type() string {
|
|||||||
return mi.config.Type
|
return mi.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mi *MIDIInput) Run(ctx context.Context) error {
|
func (mi *MIDIInput) Start(ctx context.Context) error {
|
||||||
mi.logger.Debug("running")
|
mi.logger.Debug("running")
|
||||||
defer midi.CloseDriver()
|
defer midi.CloseDriver()
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func (mo *MIDIOutput) Type() string {
|
|||||||
return mo.config.Type
|
return mo.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mo *MIDIOutput) Run(ctx context.Context) error {
|
func (mo *MIDIOutput) Start(ctx context.Context) error {
|
||||||
mo.logger.Debug("running")
|
mo.logger.Debug("running")
|
||||||
defer midi.CloseDriver()
|
defer midi.CloseDriver()
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ type ModuleError struct {
|
|||||||
type Module interface {
|
type Module interface {
|
||||||
Id() string
|
Id() string
|
||||||
Type() string
|
Type() string
|
||||||
Run(context.Context) error
|
Start(context.Context) error
|
||||||
Stop()
|
Stop()
|
||||||
Output(context.Context, any) error
|
Output(context.Context, any) error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ func (mc *MQTTClient) Type() string {
|
|||||||
return mc.config.Type
|
return mc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MQTTClient) Run(ctx context.Context) error {
|
func (mc *MQTTClient) Start(ctx context.Context) error {
|
||||||
mc.logger.Debug("running")
|
mc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func (nc *NATSClient) Type() string {
|
|||||||
return nc.config.Type
|
return nc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (nc *NATSClient) Run(ctx context.Context) error {
|
func (nc *NATSClient) Start(ctx context.Context) error {
|
||||||
nc.logger.Debug("running")
|
nc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func (pc *PSNClient) Type() string {
|
|||||||
return pc.config.Type
|
return pc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *PSNClient) Run(ctx context.Context) error {
|
func (pc *PSNClient) Start(ctx context.Context) error {
|
||||||
pc.logger.Debug("running")
|
pc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func (sc *SerialClient) SetupPort() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc *SerialClient) Run(ctx context.Context) error {
|
func (sc *SerialClient) Start(ctx context.Context) error {
|
||||||
sc.logger.Debug("running")
|
sc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func (scs *SIPCallServer) Type() string {
|
|||||||
return scs.config.Type
|
return scs.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (scs *SIPCallServer) Run(ctx context.Context) error {
|
func (scs *SIPCallServer) Start(ctx context.Context) error {
|
||||||
scs.logger.Debug("running")
|
scs.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func (sds *SIPDTMFServer) Type() string {
|
|||||||
return sds.config.Type
|
return sds.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sds *SIPDTMFServer) Run(ctx context.Context) error {
|
func (sds *SIPDTMFServer) Start(ctx context.Context) error {
|
||||||
sds.logger.Debug("running")
|
sds.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func (tc *TCPClient) Type() string {
|
|||||||
return tc.config.Type
|
return tc.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tc *TCPClient) Run(ctx context.Context) error {
|
func (tc *TCPClient) Start(ctx context.Context) error {
|
||||||
tc.logger.Debug("running")
|
tc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ ClientRead:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ts *TCPServer) Run(ctx context.Context) error {
|
func (ts *TCPServer) Start(ctx context.Context) error {
|
||||||
ts.logger.Debug("running")
|
ts.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ func (i *TimeInterval) Type() string {
|
|||||||
return i.config.Type
|
return i.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *TimeInterval) Run(ctx context.Context) error {
|
func (i *TimeInterval) Start(ctx context.Context) error {
|
||||||
i.logger.Debug("running")
|
i.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func (t *TimeTimer) Type() string {
|
|||||||
return t.config.Type
|
return t.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TimeTimer) Run(ctx context.Context) error {
|
func (t *TimeTimer) Start(ctx context.Context) error {
|
||||||
t.logger.Debug("running")
|
t.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func (uc *UDPClient) SetupConn() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (uc *UDPClient) Run(ctx context.Context) error {
|
func (uc *UDPClient) Start(ctx context.Context) error {
|
||||||
uc.logger.Debug("running")
|
uc.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func (um *UDPMulticast) Type() string {
|
|||||||
return um.config.Type
|
return um.config.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (um *UDPMulticast) Run(ctx context.Context) error {
|
func (um *UDPMulticast) Start(ctx context.Context) error {
|
||||||
um.logger.Debug("running")
|
um.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ func (us *UDPServer) Type() string {
|
|||||||
return us.config.Id
|
return us.config.Id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (us *UDPServer) Run(ctx context.Context) error {
|
func (us *UDPServer) Start(ctx context.Context) error {
|
||||||
us.logger.Debug("running")
|
us.logger.Debug("running")
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
|
|||||||
@@ -58,13 +58,13 @@ func (r *Router) removeModule(moduleId string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) runModule(ctx context.Context, moduleId string) error {
|
func (r *Router) startModule(ctx context.Context, moduleId string) error {
|
||||||
moduleInstance := r.getModule(moduleId)
|
moduleInstance := r.getModule(moduleId)
|
||||||
if moduleInstance == nil {
|
if moduleInstance == nil {
|
||||||
return errors.New("module id not found")
|
return errors.New("module id not found")
|
||||||
}
|
}
|
||||||
r.moduleWait.Go(func() {
|
r.moduleWait.Go(func() {
|
||||||
err := moduleInstance.Run(ctx)
|
err := moduleInstance.Start(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(jwetzell): propagate module run errors better
|
// TODO(jwetzell): propagate module run errors better
|
||||||
r.logger.Error("error encountered running module", "moduleId", moduleId, "error", err)
|
r.logger.Error("error encountered running module", "moduleId", moduleId, "error", err)
|
||||||
@@ -148,7 +148,7 @@ func NewRouter(config config.Config, tracer trace.Tracer) (*Router, []module.Mod
|
|||||||
return &router, moduleErrors, routeErrors
|
return &router, moduleErrors, routeErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Router) Run(ctx context.Context) {
|
func (r *Router) Start(ctx context.Context) {
|
||||||
r.logger.Info("running")
|
r.logger.Info("running")
|
||||||
routerContext, cancel := context.WithCancel(ctx)
|
routerContext, cancel := context.WithCancel(ctx)
|
||||||
r.Context = routerContext
|
r.Context = routerContext
|
||||||
@@ -157,7 +157,7 @@ func (r *Router) Run(ctx context.Context) {
|
|||||||
|
|
||||||
for moduleId := range r.ModuleInstances {
|
for moduleId := range r.ModuleInstances {
|
||||||
// TODO(jwetzell): handle module run errors
|
// TODO(jwetzell): handle module run errors
|
||||||
r.runModule(contextWithRouter, moduleId)
|
r.startModule(contextWithRouter, moduleId)
|
||||||
}
|
}
|
||||||
<-r.Context.Done()
|
<-r.Context.Done()
|
||||||
r.logger.Debug("waiting for modules to exit")
|
r.logger.Debug("waiting for modules to exit")
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func (mcm *MockCounterModule) Output(context.Context, any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mcm *MockCounterModule) Run(ctx context.Context) error {
|
func (mcm *MockCounterModule) Start(ctx context.Context) error {
|
||||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
@@ -173,7 +173,7 @@ func TestRouterInputSingleRoute(t *testing.T) {
|
|||||||
routerRunner := sync.WaitGroup{}
|
routerRunner := sync.WaitGroup{}
|
||||||
|
|
||||||
routerRunner.Go(func() {
|
routerRunner.Go(func() {
|
||||||
router.Run(t.Context())
|
router.Start(t.Context())
|
||||||
fmt.Println("router stopped")
|
fmt.Println("router stopped")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ func TestRouterInputMultipleRoutes(t *testing.T) {
|
|||||||
routerRunner := sync.WaitGroup{}
|
routerRunner := sync.WaitGroup{}
|
||||||
|
|
||||||
routerRunner.Go(func() {
|
routerRunner.Go(func() {
|
||||||
router.Run(t.Context())
|
router.Start(t.Context())
|
||||||
})
|
})
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|
||||||
@@ -316,7 +316,7 @@ func TestRouterInputMultipleModules(t *testing.T) {
|
|||||||
routerRunner := sync.WaitGroup{}
|
routerRunner := sync.WaitGroup{}
|
||||||
|
|
||||||
routerRunner.Go(func() {
|
routerRunner.Go(func() {
|
||||||
router.Run(t.Context())
|
router.Start(t.Context())
|
||||||
})
|
})
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user