mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 12:55:29 +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.Go(func() {
|
||||
router.Run(context.Background())
|
||||
router.Start(context.Background())
|
||||
})
|
||||
|
||||
<-ctx.Done()
|
||||
|
||||
@@ -38,7 +38,7 @@ func (hc *HTTPClient) Type() string {
|
||||
return hc.config.Type
|
||||
}
|
||||
|
||||
func (hc *HTTPClient) Run(ctx context.Context) error {
|
||||
func (hc *HTTPClient) Start(ctx context.Context) error {
|
||||
hc.logger.Debug("running")
|
||||
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")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (mi *MIDIInput) Type() string {
|
||||
return mi.config.Type
|
||||
}
|
||||
|
||||
func (mi *MIDIInput) Run(ctx context.Context) error {
|
||||
func (mi *MIDIInput) Start(ctx context.Context) error {
|
||||
mi.logger.Debug("running")
|
||||
defer midi.CloseDriver()
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
@@ -55,7 +55,7 @@ func (mo *MIDIOutput) Type() string {
|
||||
return mo.config.Type
|
||||
}
|
||||
|
||||
func (mo *MIDIOutput) Run(ctx context.Context) error {
|
||||
func (mo *MIDIOutput) Start(ctx context.Context) error {
|
||||
mo.logger.Debug("running")
|
||||
defer midi.CloseDriver()
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
@@ -18,7 +18,7 @@ type ModuleError struct {
|
||||
type Module interface {
|
||||
Id() string
|
||||
Type() string
|
||||
Run(context.Context) error
|
||||
Start(context.Context) error
|
||||
Stop()
|
||||
Output(context.Context, any) error
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (mc *MQTTClient) Type() string {
|
||||
return mc.config.Type
|
||||
}
|
||||
|
||||
func (mc *MQTTClient) Run(ctx context.Context) error {
|
||||
func (mc *MQTTClient) Start(ctx context.Context) error {
|
||||
mc.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func (nc *NATSClient) Type() string {
|
||||
return nc.config.Type
|
||||
}
|
||||
|
||||
func (nc *NATSClient) Run(ctx context.Context) error {
|
||||
func (nc *NATSClient) Start(ctx context.Context) error {
|
||||
nc.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ func (pc *PSNClient) Type() string {
|
||||
return pc.config.Type
|
||||
}
|
||||
|
||||
func (pc *PSNClient) Run(ctx context.Context) error {
|
||||
func (pc *PSNClient) Start(ctx context.Context) error {
|
||||
pc.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func (sc *SerialClient) SetupPort() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (sc *SerialClient) Run(ctx context.Context) error {
|
||||
func (sc *SerialClient) Start(ctx context.Context) error {
|
||||
sc.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ func (scs *SIPCallServer) Type() string {
|
||||
return scs.config.Type
|
||||
}
|
||||
|
||||
func (scs *SIPCallServer) Run(ctx context.Context) error {
|
||||
func (scs *SIPCallServer) Start(ctx context.Context) error {
|
||||
scs.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ func (sds *SIPDTMFServer) Type() string {
|
||||
return sds.config.Type
|
||||
}
|
||||
|
||||
func (sds *SIPDTMFServer) Run(ctx context.Context) error {
|
||||
func (sds *SIPDTMFServer) Start(ctx context.Context) error {
|
||||
sds.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ func (tc *TCPClient) Type() string {
|
||||
return tc.config.Type
|
||||
}
|
||||
|
||||
func (tc *TCPClient) Run(ctx context.Context) error {
|
||||
func (tc *TCPClient) Start(ctx context.Context) error {
|
||||
tc.logger.Debug("running")
|
||||
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")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ func (i *TimeInterval) Type() string {
|
||||
return i.config.Type
|
||||
}
|
||||
|
||||
func (i *TimeInterval) Run(ctx context.Context) error {
|
||||
func (i *TimeInterval) Start(ctx context.Context) error {
|
||||
i.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ func (t *TimeTimer) Type() string {
|
||||
return t.config.Type
|
||||
}
|
||||
|
||||
func (t *TimeTimer) Run(ctx context.Context) error {
|
||||
func (t *TimeTimer) Start(ctx context.Context) error {
|
||||
t.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -73,7 +73,7 @@ func (uc *UDPClient) SetupConn() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (uc *UDPClient) Run(ctx context.Context) error {
|
||||
func (uc *UDPClient) Start(ctx context.Context) error {
|
||||
uc.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ func (um *UDPMulticast) Type() string {
|
||||
return um.config.Type
|
||||
}
|
||||
|
||||
func (um *UDPMulticast) Run(ctx context.Context) error {
|
||||
func (um *UDPMulticast) Start(ctx context.Context) error {
|
||||
um.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ func (us *UDPServer) Type() string {
|
||||
return us.config.Id
|
||||
}
|
||||
|
||||
func (us *UDPServer) Run(ctx context.Context) error {
|
||||
func (us *UDPServer) Start(ctx context.Context) error {
|
||||
us.logger.Debug("running")
|
||||
router, ok := ctx.Value(route.RouterContextKey).(route.RouteIO)
|
||||
|
||||
|
||||
@@ -58,13 +58,13 @@ func (r *Router) removeModule(moduleId string) error {
|
||||
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)
|
||||
if moduleInstance == nil {
|
||||
return errors.New("module id not found")
|
||||
}
|
||||
r.moduleWait.Go(func() {
|
||||
err := moduleInstance.Run(ctx)
|
||||
err := moduleInstance.Start(ctx)
|
||||
if err != nil {
|
||||
// TODO(jwetzell): propagate module run errors better
|
||||
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
|
||||
}
|
||||
|
||||
func (r *Router) Run(ctx context.Context) {
|
||||
func (r *Router) Start(ctx context.Context) {
|
||||
r.logger.Info("running")
|
||||
routerContext, cancel := context.WithCancel(ctx)
|
||||
r.Context = routerContext
|
||||
@@ -157,7 +157,7 @@ func (r *Router) Run(ctx context.Context) {
|
||||
|
||||
for moduleId := range r.ModuleInstances {
|
||||
// TODO(jwetzell): handle module run errors
|
||||
r.runModule(contextWithRouter, moduleId)
|
||||
r.startModule(contextWithRouter, moduleId)
|
||||
}
|
||||
<-r.Context.Done()
|
||||
r.logger.Debug("waiting for modules to exit")
|
||||
|
||||
@@ -37,7 +37,7 @@ func (mcm *MockCounterModule) Output(context.Context, any) error {
|
||||
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)
|
||||
|
||||
if !ok {
|
||||
@@ -173,7 +173,7 @@ func TestRouterInputSingleRoute(t *testing.T) {
|
||||
routerRunner := sync.WaitGroup{}
|
||||
|
||||
routerRunner.Go(func() {
|
||||
router.Run(t.Context())
|
||||
router.Start(t.Context())
|
||||
fmt.Println("router stopped")
|
||||
})
|
||||
|
||||
@@ -245,7 +245,7 @@ func TestRouterInputMultipleRoutes(t *testing.T) {
|
||||
routerRunner := sync.WaitGroup{}
|
||||
|
||||
routerRunner.Go(func() {
|
||||
router.Run(t.Context())
|
||||
router.Start(t.Context())
|
||||
})
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
@@ -316,7 +316,7 @@ func TestRouterInputMultipleModules(t *testing.T) {
|
||||
routerRunner := sync.WaitGroup{}
|
||||
|
||||
routerRunner.Go(func() {
|
||||
router.Run(t.Context())
|
||||
router.Start(t.Context())
|
||||
})
|
||||
|
||||
time.Sleep(time.Second * 1)
|
||||
|
||||
Reference in New Issue
Block a user