There is a job that I want to be resident and execute regularly, but if it is a normal ticker, the interval count starts from the time the ticker is created after starting it, so the time cannot be set exactly. Moreover, even if the ticker was set to interval so that it would be 12:00:00, it would occasionally move at 11: 59: 59.999, and the processed data would be duplicated and registered.
https://github.com/xbridges/Scheduler Simply, the ticker will call it exactly at the specified time interval.
ex) sch, next := NewScheduler(3600, 0)
If you start like this, the ticker will fire once every hour. Furthermore, if you use the offset value, the interval is every hour (3600), but if you set offset: 600, the ticker will fire at 05 minutes every hour.
I'm just wrapping the ticker, but Kimo
is := time.Duration(interval) * time.Second // <--Set the specified time to Duration
n := time.Now() // <--Current time
ns := n.Round(is) // <--It feels like masking the current time with an interval time and rounding it.
If you do this, the ticker will occasionally move early, and even if it reaches 59 minutes 59 seconds .9999, it will be rounded off, so the time will properly fire at the next 00 minutes.
I made a note because it was running regularly and I was a little addicted to it.
http://okzk.hatenablog.com/entry/2015/12/01/001924
Recommended Posts