second to nanosecond

This commit is contained in:
Pavel 2024-05-20 12:36:04 +03:00
parent 337fa4607a
commit b18d3586f1
2 changed files with 3 additions and 7 deletions

@ -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
}

@ -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
}