Skip to content
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

Job is not scheduled immediately #396

Closed
beantowel opened this issue Jun 20, 2021 · 4 comments
Closed

Job is not scheduled immediately #396

beantowel opened this issue Jun 20, 2021 · 4 comments

Comments

@beantowel
Copy link

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()
}
@jenskueper
Copy link

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

@robfig
Copy link
Owner

robfig commented Oct 1, 2021

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.

@alekc
Copy link

alekc commented Oct 7, 2021

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

@zeewell
Copy link

zeewell commented Apr 22, 2022

#436

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants