43 lines
863 B
Go
43 lines
863 B
Go
package recorder
|
|
|
|
import (
|
|
"context"
|
|
"sync"
|
|
|
|
"go.opentelemetry.io/otel/metric"
|
|
"go.opentelemetry.io/otel/trace"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel"
|
|
|
|
"gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather"
|
|
)
|
|
|
|
type WeatherRecorder struct {
|
|
updates []*weather.WeatherUpdate
|
|
keep int
|
|
ctx context.Context
|
|
tracer trace.Tracer
|
|
meter metric.Meter
|
|
*sync.RWMutex
|
|
}
|
|
|
|
type Opts struct {
|
|
Ctx context.Context
|
|
KeepLast int
|
|
}
|
|
|
|
func NewWeatherRecorder(opts *Opts) *WeatherRecorder {
|
|
if opts.KeepLast < 1 {
|
|
opts.KeepLast = 1
|
|
}
|
|
|
|
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{},
|
|
}
|
|
}
|