From 971eea6e4111fcc998c96f2ae1fc675a696a051f Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Wed, 24 Dec 2025 16:32:44 -0600 Subject: [PATCH] add a processor that sleeps --- internal/processor/time-sleep.go | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 internal/processor/time-sleep.go diff --git a/internal/processor/time-sleep.go b/internal/processor/time-sleep.go new file mode 100644 index 0000000..631692a --- /dev/null +++ b/internal/processor/time-sleep.go @@ -0,0 +1,47 @@ +package processor + +import ( + "context" + "errors" + "log/slog" + "time" + + "github.com/jwetzell/showbridge-go/internal/config" +) + +type MetaDelay struct { + config config.ProcessorConfig + logger *slog.Logger + Duration time.Duration +} + +func (md *MetaDelay) Process(ctx context.Context, payload any) (any, error) { + time.Sleep(md.Duration) + return payload, nil +} + +func (md *MetaDelay) Type() string { + return md.config.Type +} + +func init() { + RegisterProcessor(ProcessorRegistration{ + Type: "time.sleep", + New: func(config config.ProcessorConfig) (Processor, error) { + params := config.Params + + duration, ok := params["duration"] + if !ok { + return nil, errors.New("time.sleep requires a duration parameter") + } + + durationNum, ok := duration.(float64) + + if !ok { + return nil, errors.New("time.sleep duration must be number") + } + + return &MetaDelay{config: config, Duration: time.Millisecond * time.Duration(durationNum), logger: slog.Default().With("component", "processor")}, nil + }, + }) +}