forked from gsn/predictor
51 lines
924 B
Go
51 lines
924 B
Go
package updater
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"git.intra.yksa.space/gsn/predictor/internal/pkg/errcodes"
|
|
"git.intra.yksa.space/gsn/predictor/internal/pkg/log"
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type Job struct {
|
|
service GribService
|
|
config *Config
|
|
}
|
|
|
|
func New(service GribService, config *Config) *Job {
|
|
return &Job{
|
|
service: service,
|
|
config: config,
|
|
}
|
|
}
|
|
|
|
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 1
|
|
}
|
|
|
|
func (j *Job) GetAsync() bool {
|
|
return false
|
|
}
|
|
|
|
func (j *Job) Execute(ctx context.Context) error {
|
|
log := log.Ctx(ctx)
|
|
log.Info("executing GRIB update job")
|
|
|
|
if err := j.service.Update(ctx); err != nil {
|
|
log.Error("GRIB update failed", zap.Error(err))
|
|
return errcodes.Wrap(err, "failed to update GRIB data")
|
|
}
|
|
|
|
log.Info("GRIB update completed successfully")
|
|
return nil
|
|
}
|