make an OutputModule interface and remove output from modules that don't implement it

This commit is contained in:
Joel Wetzell
2026-03-18 16:24:19 -05:00
parent 3fedb7ac92
commit 2fbca6209e
8 changed files with 15 additions and 28 deletions

View File

@@ -10,6 +10,9 @@ type Module interface {
Type() string
Start(context.Context) error
Stop()
}
type OutputModule interface {
Output(context.Context, any) error
}

View File

@@ -82,10 +82,6 @@ func (mi *MIDIInput) Start(ctx context.Context) error {
return nil
}
func (mi *MIDIInput) Output(ctx context.Context, payload any) error {
return errors.New("midi.input output is not implemented")
}
func (mi *MIDIInput) Stop() {
mi.cancel()
}

View File

@@ -102,10 +102,6 @@ func (ns *NATSServer) Start(ctx context.Context) error {
return nil
}
func (ns *NATSServer) Output(ctx context.Context, payload any) error {
return errors.New("nats.server does not support output")
}
func (ns *NATSServer) Stop() {
ns.cancel()
if ns.server != nil {

View File

@@ -3,7 +3,6 @@ package module
import (
"context"
"errors"
"fmt"
"log/slog"
"net"
"time"
@@ -105,10 +104,6 @@ func (pc *PSNClient) Start(ctx context.Context) error {
}
}
func (pc *PSNClient) Output(ctx context.Context, payload any) error {
return fmt.Errorf("psn.client output is not implemented")
}
func (pc *PSNClient) Stop() {
pc.cancel()
}

View File

@@ -12,10 +12,6 @@ import (
type TestModule struct {
}
func (m *TestModule) Output(ctx context.Context, payload any) error {
return nil
}
func (m *TestModule) Start(ctx context.Context) error {
<-ctx.Done()
return nil

View File

@@ -74,11 +74,6 @@ func (i *TimeInterval) Start(ctx context.Context) error {
}
func (i *TimeInterval) Output(ctx context.Context, payload any) error {
i.ticker.Reset(time.Millisecond * time.Duration(i.Duration))
return nil
}
func (i *TimeInterval) Stop() {
i.cancel()
}

View File

@@ -73,11 +73,6 @@ func (t *TimeTimer) Start(ctx context.Context) error {
}
}
func (t *TimeTimer) Output(ctx context.Context, payload any) error {
t.timer.Reset(time.Millisecond * time.Duration(t.Duration))
return nil
}
func (t *TimeTimer) Stop() {
t.cancel()
}

View File

@@ -269,9 +269,20 @@ func (r *Router) HandleOutput(ctx context.Context, destinationId string, payload
return err
}
outputModule, ok := destinationModule.(common.OutputModule)
if !ok {
err := errors.New("module does not support output")
span.SetStatus(codes.Error, err.Error())
span.RecordError(err)
r.logger.Error("module does not support output", "destinationId", destinationId)
outputEvent.Error = err.Error()
r.broadcastEvent(outputEvent)
return err
}
moduleOutputCtx, moduleOutputSpan := otel.Tracer("module").Start(spanCtx, "output", trace.WithAttributes(attribute.String("module.id", destinationModule.Id()), attribute.String("module.type", destinationModule.Type())))
defer moduleOutputSpan.End()
err := destinationModule.Output(moduleOutputCtx, payload)
err := outputModule.Output(moduleOutputCtx, payload)
if err != nil {
moduleOutputSpan.SetStatus(codes.Error, err.Error())
moduleOutputSpan.RecordError(err)