stillbox/pkg/sinks/database.go

35 lines
730 B
Go
Raw Normal View History

2024-08-01 01:01:08 -04:00
package sinks
import (
"context"
2024-08-05 18:11:31 -04:00
"dynatron.me/x/stillbox/pkg/calls"
"dynatron.me/x/stillbox/pkg/calls/callstore"
2024-11-03 07:19:03 -05:00
"dynatron.me/x/stillbox/pkg/database"
"dynatron.me/x/stillbox/pkg/talkgroups/tgstore"
2024-08-01 01:01:08 -04:00
"github.com/rs/zerolog/log"
)
type DatabaseSink struct {
2024-11-21 13:23:21 -05:00
db database.Store
tgs tgstore.Store
2024-08-01 01:01:08 -04:00
}
func NewDatabaseSink(store database.Store, tgs tgstore.Store) *DatabaseSink {
return &DatabaseSink{store, tgs}
2024-08-01 01:01:08 -04:00
}
func (s *DatabaseSink) Call(ctx context.Context, call *calls.Call) error {
2024-08-18 08:44:44 -04:00
if !call.ShouldStore() {
log.Debug().Str("call", call.String()).Msg("received dontStore call")
return nil
}
return callstore.FromCtx(ctx).AddCall(ctx, call)
2024-08-01 01:01:08 -04:00
}
func (s *DatabaseSink) SinkType() string {
return "database"
}