cron
cron copied to clipboard
cron does not support system time change??
if change system time, cron do not work again!!!
have same problem too. any suggestions ?
have same problem too. any suggestions ?
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 * * ?" 1.when the application is running, change the system time before now, it didn't work, but if i change the system time after now, it running. for example, the real system time is 2019-06-04 22:58:59, when 2019-06-04 23:00:00, the cron run.but if i change system time to 2019-06-03 22:28:59, the cron didn't work. but if i change system time to 2019-06-05 23:58:59 or 06-06..., the cron run.
2.my application is stoped. i start my application after i changed the system time, the cron runs . for example:the real time is 2019-06-04 22:58:59, and i change it to 2019-06-03 22:58:59, and then i run my application, when 2019-06-03 23:00:00, the cron runs. that is to say, changing the time before restarting will take effect.
3.my final choice is using the time.NewTicker() ticker := time.NewTicker(time.Second) for { select { case <- ticker.C: fmt.Println("hello katy") } }
cron is support system time change I may give you some tips. If you want set everyday when 00:01:00 the cron runs . you just set spec:="0 1 0 1/1 * ?",when now is 2019-08-15 00:00:00.so when you wait one minute the cron runs.but for next runs,You have to change the system time between the initiation of the task and the first execution.You know it work time is the cron runs next second will get now time again,then it will run in this change system time
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)
}
}()