cron
cron copied to clipboard
Job is not scheduled immediately
Job is not scheduled as described as in the doc
You may also schedule a job to execute at fixed intervals, starting at the time it's added or cron is run
For example, the code below will only print once "cron scheduled" instead of twice as expected.
func TestCron(t *testing.T) {
c := cron.New()
c.Start()
c.AddFunc("@every 15s", func() {
t.Logf("cron scheduled")
})
time.Sleep(time.Second * 20)
c.Stop()
}
The docs might not be 100% clear, but its says that it only starts after the defined interval. Quote from the docs: "For example, "@every 1h30m10s" would indicate a schedule that activates after 1 hour, 30 minutes, 10 seconds, and then every interval after that."
I agree this is confusing and the documentation should be clarified. I don't think I can change it now, though, since that would be backwards incompatible. On the bright side, Schedule
is an interface so nothing stops you from creating your own implementation that behaves in this manner.
@robfig what about introducing an opt-in flag? This way it would be backwards compatible.
#436