forked from gsn/predictor
51 lines
992 B
Go
51 lines
992 B
Go
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
|
|
}
|