diff --git a/internal/workers/data_updater/data_updater.go b/internal/workers/data_updater/data_updater.go index a978290..93ae13a 100644 --- a/internal/workers/data_updater/data_updater.go +++ b/internal/workers/data_updater/data_updater.go @@ -27,7 +27,7 @@ func NewDataUpdaterWC(deps Deps) *DataUpdater { func (wc *DataUpdater) Start(ctx context.Context) { nextStart := calculateTime() - ticker := time.NewTicker(time.Second * time.Duration(nextStart)) + ticker := time.NewTicker(time.Nanosecond * time.Duration(nextStart)) //ticker := time.NewTicker(10 * time.Second) defer ticker.Stop() @@ -36,10 +36,7 @@ func (wc *DataUpdater) Start(ctx context.Context) { case <-ticker.C: wc.processTasks(ctx) nextStart = calculateTime() - if nextStart <= 0 { - nextStart = 86400 - } - ticker.Reset(time.Second * time.Duration(nextStart)) + ticker.Reset(time.Nanosecond * time.Duration(nextStart)) case <-ctx.Done(): return } diff --git a/internal/workers/data_updater/timer.go b/internal/workers/data_updater/timer.go index 940f470..ae4a113 100644 --- a/internal/workers/data_updater/timer.go +++ b/internal/workers/data_updater/timer.go @@ -8,13 +8,12 @@ func calculateTime() int64 { now := time.Now() targetTime := time.Date(now.Year(), now.Month(), now.Day(), 4, 0, 0, 0, now.Location()) - if now.After(targetTime) { targetTime = targetTime.AddDate(0, 0, 1) } toTarget := targetTime.Sub(now) - sec := int64(toTarget.Seconds()) + sec := toTarget.Nanoseconds() return sec }