feat: downloader

This commit is contained in:
Anatoly Antonov 2025-06-23 04:19:26 +03:00
parent b9c1a98895
commit 42e7924be9
37 changed files with 2422 additions and 94 deletions

View file

@ -0,0 +1,8 @@
package updater
import "time"
type Config struct {
Interval time.Duration `env:"INTERVAL" envDefault:"6h"`
Timeout time.Duration `env:"TIMEOUT" envDefault:"45m"`
}

View file

@ -0,0 +1,8 @@
package updater
import "context"
// GribService defines the interface for GRIB operations needed by the updater job
type GribService interface {
Update(ctx context.Context) error
}

View file

@ -0,0 +1,51 @@
package updater
import (
"context"
"time"
"git.intra.yksa.space/gsn/predictor/internal/pkg/errcodes"
"go.uber.org/zap"
)
type Job struct {
service GribService
config *Config
logger *zap.Logger
}
func New(service GribService, config *Config, logger *zap.Logger) *Job {
return &Job{
service: service,
config: config,
logger: logger,
}
}
func (j *Job) GetInterval() time.Duration {
return j.config.Interval
}
func (j *Job) GetTimeout() time.Duration {
return j.config.Timeout
}
func (j *Job) GetCount() int {
return 0 // Run indefinitely
}
func (j *Job) GetAsync() bool {
return false // Singleton mode - only one instance should run
}
func (j *Job) Execute(ctx context.Context) error {
j.logger.Info("executing GRIB update job")
if err := j.service.Update(ctx); err != nil {
j.logger.Error("GRIB update failed", zap.Error(err))
return errcodes.Wrap(err, "failed to update GRIB data")
}
j.logger.Info("GRIB update completed successfully")
return nil
}