-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cron does not support system time change?? #154
Comments
have same problem too. |
1 similar comment
have same problem too. |
What is the behavior that you observe? I believe that cron would run the next job at the originally-scheduled time (before the time change), and then it would schedule the next job for an accurate time (after the time change). Is that what you observe? The only way I can think of to detect that the system time has changed is to have a dedicated goroutine that sleeps for known periods of time and compares (time at start of sleep + duration of sleep) to (time.Now). Is there any other way? I'm not sure.. I don't perceive this as a significant-enough use case to merit the effort and complication of solving it. What is your use case, that results in this being a problem? |
spec := "0 0 23 * * ?" 2.my application is stoped. i start my application after i changed the system time, the cron runs . 3.my final choice is using the time.NewTicker() |
cron is support system time change |
I had a utility that used this package set as a startup program on a raspberry pi. Since Pis do not have a hardware clock, they synchronise with the network time at booting up. My utility would be started before this synchronisation and hence would schedule jobs at the wrong time. The fix I ended up deploying was to fetch the network time in my utility and compare it with the system time before starting the cron scheduler. Also, before deploying the fix, I did notice that as per robfig's prediction, the consecutive schedules would run at the correct times. |
My solution is to start another goroutine. If the system time changed greatly, it can detect it. var last = time.Time{}
go func() {
for {
var tm = time.Now()
if last.Year() != 1 {
var diffSec = tm.Unix() - last.Unix()
if diffSec > 10 || diffSec < -10 {
task.Stop()
task.Start()
}
}
last = tm
time.Sleep(10 * time.Second)
}
}() |
if change system time, cron do not work again!!!
The text was updated successfully, but these errors were encountered: