stillbox/pkg/gordio/sinks/sinks.go

42 lines
729 B
Go
Raw Normal View History

2024-08-01 01:01:08 -04:00
package sinks
import (
"context"
2024-08-04 10:56:46 -04:00
2024-08-05 18:11:31 -04:00
"dynatron.me/x/stillbox/pkg/calls"
2024-08-01 01:01:08 -04:00
"github.com/rs/zerolog/log"
)
type Sink interface {
Call(context.Context, *calls.Call) error
SinkType() string
}
type sinkInstance struct {
Sink
Name string
}
type Sinks []sinkInstance
func (s *Sinks) Register(name string, toAdd Sink) {
*s = append(*s, sinkInstance{
Name: name,
Sink: toAdd,
})
}
func (s *Sinks) EmitCall(ctx context.Context, call *calls.Call) {
2024-08-04 10:56:46 -04:00
for i := range *s {
go (*s)[i].emitCallLogErr(ctx, call)
2024-08-01 01:01:08 -04:00
}
}
func (sink *sinkInstance) emitCallLogErr(ctx context.Context, call *calls.Call) {
err := sink.Call(ctx, call)
if err != nil {
log.Error().Str("sink", sink.Name).Err(err).Msg("call emit to sink failed")
}
}