feat: downloader
This commit is contained in:
parent
b9c1a98895
commit
42e7924be9
37 changed files with 2422 additions and 94 deletions
|
|
@ -2,21 +2,56 @@ package service
|
|||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
redis Redis
|
||||
downloader Downloader
|
||||
cfg *Config
|
||||
redis Redis
|
||||
grib Grib
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
func New(redis Redis, downloader Downloader) *Service {
|
||||
return &Service{
|
||||
redis: redis,
|
||||
downloader: downloader,
|
||||
func New(cfg *Config, gribService Grib, redisService Redis, logger *zap.Logger) (*Service, error) {
|
||||
svc := &Service{
|
||||
cfg: cfg,
|
||||
redis: redisService,
|
||||
grib: gribService,
|
||||
logger: logger,
|
||||
}
|
||||
|
||||
return svc, nil
|
||||
}
|
||||
|
||||
// DownloadWeatherData downloads weather forecast data using the configured downloader
|
||||
func (s *Service) DownloadWeatherData(ctx context.Context) error {
|
||||
return s.downloader.Download(ctx)
|
||||
// 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() {
|
||||
s.logger.Info("service started")
|
||||
}
|
||||
|
||||
// Stop stops the service
|
||||
func (s *Service) Stop() {
|
||||
s.logger.Info("service stopped")
|
||||
}
|
||||
|
||||
// Close closes the service and releases resources
|
||||
func (s *Service) Close() error {
|
||||
s.Stop()
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue