cron icon indicating copy to clipboard operation
cron copied to clipboard

Job is not scheduled immediately

Open beantowel opened this issue 3 years ago • 4 comments

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()
}

beantowel avatar Jun 20 '21 12:06 beantowel

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."

jenskueper avatar Jul 14 '21 06:07 jenskueper

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 avatar Oct 01 '21 21:10 robfig

@robfig what about introducing an opt-in flag? This way it would be backwards compatible.

alekc avatar Oct 07 '21 08:10 alekc

#436

zeewell avatar Apr 22 '22 03:04 zeewell