forked from gsn/predictor
feat: downloader
This commit is contained in:
parent
b9c1a98895
commit
42e7924be9
37 changed files with 2422 additions and 94 deletions
8
internal/jobs/grib/updater/config.go
Normal file
8
internal/jobs/grib/updater/config.go
Normal 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"`
|
||||
}
|
||||
8
internal/jobs/grib/updater/deps.go
Normal file
8
internal/jobs/grib/updater/deps.go
Normal 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
|
||||
}
|
||||
51
internal/jobs/grib/updater/updater.go
Normal file
51
internal/jobs/grib/updater/updater.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue