move recorder to interface
This commit is contained in:
@ -9,20 +9,21 @@ import (
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
||||
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders"
|
||||
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders/memory"
|
||||
)
|
||||
|
||||
type WeatherRecorder struct {
|
||||
updates []*weather.WeatherUpdate
|
||||
keep int
|
||||
ctx context.Context
|
||||
tracer trace.Tracer
|
||||
meter metric.Meter
|
||||
recorder recorders.Recorder
|
||||
ctx context.Context
|
||||
tracer trace.Tracer
|
||||
meter metric.Meter
|
||||
*sync.RWMutex
|
||||
}
|
||||
|
||||
type Opts struct {
|
||||
Ctx context.Context
|
||||
Recorder recorders.Recorder // If nil, will use memory recorder
|
||||
KeepLast int
|
||||
}
|
||||
|
||||
@ -31,12 +32,20 @@ func NewWeatherRecorder(opts *Opts) *WeatherRecorder {
|
||||
opts.KeepLast = 1
|
||||
}
|
||||
|
||||
if opts.Recorder == nil {
|
||||
opts.Recorder = &memory.MemoryRecorder{}
|
||||
}
|
||||
|
||||
opts.Recorder.Init(opts.Ctx, &recorders.RecorderOpts{
|
||||
RetainLast: opts.KeepLast,
|
||||
BaseCtx: opts.Ctx,
|
||||
})
|
||||
|
||||
return &WeatherRecorder{
|
||||
updates: make([]*weather.WeatherUpdate, 0, opts.KeepLast),
|
||||
keep: opts.KeepLast,
|
||||
ctx: opts.Ctx,
|
||||
tracer: otel.GetTracer(opts.Ctx, "weatherRecorder"),
|
||||
meter: otel.GetMeter(opts.Ctx, "weatherRecorder"),
|
||||
RWMutex: &sync.RWMutex{},
|
||||
ctx: opts.Ctx,
|
||||
recorder: opts.Recorder,
|
||||
tracer: otel.GetTracer(opts.Ctx, "weatherRecorder"),
|
||||
meter: otel.GetMeter(opts.Ctx, "weatherRecorder"),
|
||||
RWMutex: &sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user