second to nanosecond
This commit is contained in:
parent
337fa4607a
commit
b18d3586f1
@ -27,7 +27,7 @@ func NewDataUpdaterWC(deps Deps) *DataUpdater {
|
|||||||
|
|
||||||
func (wc *DataUpdater) Start(ctx context.Context) {
|
func (wc *DataUpdater) Start(ctx context.Context) {
|
||||||
nextStart := calculateTime()
|
nextStart := calculateTime()
|
||||||
ticker := time.NewTicker(time.Second * time.Duration(nextStart))
|
ticker := time.NewTicker(time.Nanosecond * time.Duration(nextStart))
|
||||||
//ticker := time.NewTicker(10 * time.Second)
|
//ticker := time.NewTicker(10 * time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
|
||||||
@ -36,10 +36,7 @@ func (wc *DataUpdater) Start(ctx context.Context) {
|
|||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
wc.processTasks(ctx)
|
wc.processTasks(ctx)
|
||||||
nextStart = calculateTime()
|
nextStart = calculateTime()
|
||||||
if nextStart <= 0 {
|
ticker.Reset(time.Nanosecond * time.Duration(nextStart))
|
||||||
nextStart = 86400
|
|
||||||
}
|
|
||||||
ticker.Reset(time.Second * time.Duration(nextStart))
|
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,12 @@ func calculateTime() int64 {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
targetTime := time.Date(now.Year(), now.Month(), now.Day(), 4, 0, 0, 0, now.Location())
|
targetTime := time.Date(now.Year(), now.Month(), now.Day(), 4, 0, 0, 0, now.Location())
|
||||||
|
|
||||||
if now.After(targetTime) {
|
if now.After(targetTime) {
|
||||||
targetTime = targetTime.AddDate(0, 0, 1)
|
targetTime = targetTime.AddDate(0, 0, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
toTarget := targetTime.Sub(now)
|
toTarget := targetTime.Sub(now)
|
||||||
sec := int64(toTarget.Seconds())
|
sec := toTarget.Nanoseconds()
|
||||||
|
|
||||||
return sec
|
return sec
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user