64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.intra.yksa.space/gsn/predictor/internal/pkg/log"
|
|
)
|
|
|
|
type Service struct {
|
|
cfg *Config
|
|
redis Redis
|
|
grib Grib
|
|
}
|
|
|
|
func New(cfg *Config, gribService Grib, redisService Redis) (*Service, error) {
|
|
svc := &Service{
|
|
cfg: cfg,
|
|
redis: redisService,
|
|
grib: gribService,
|
|
}
|
|
|
|
return svc, nil
|
|
}
|
|
|
|
// UpdateWeatherData updates weather forecast data using the configured grib service
|
|
func (s *Service) UpdateWeatherData(ctx context.Context) error {
|
|
return s.grib.Update(ctx)
|
|
}
|
|
|
|
// ExtractWind extracts wind data for given coordinates and time
|
|
func (s *Service) ExtractWind(ctx context.Context, lat, lon, alt float64, ts time.Time) ([2]float64, error) {
|
|
return s.grib.Extract(ctx, lat, lon, alt, ts)
|
|
}
|
|
|
|
// Update updates the GRIB data (implements updater.GribService)
|
|
func (s *Service) Update(ctx context.Context) error {
|
|
return s.UpdateWeatherData(ctx)
|
|
}
|
|
|
|
// Start starts the service
|
|
func (s *Service) Start() {
|
|
log.Ctx(context.Background()).Info("service started")
|
|
}
|
|
|
|
// Stop stops the service
|
|
func (s *Service) Stop() {
|
|
log.Ctx(context.Background()).Info("service stopped")
|
|
}
|
|
|
|
// Close closes the service and releases resources
|
|
func (s *Service) Close() error {
|
|
s.Stop()
|
|
return nil
|
|
}
|
|
|
|
func (s *Service) GetGribStatus(ctx context.Context) (ready bool, lastUpdate time.Time, isFresh bool, errMsg string) {
|
|
if gribStatus, ok := s.grib.(interface {
|
|
GetStatus() (ready bool, lastUpdate time.Time, isFresh bool, errMsg string)
|
|
}); ok {
|
|
return gribStatus.GetStatus()
|
|
}
|
|
return false, time.Time{}, false, "grib service does not implement GetStatus"
|
|
}
|