Skip to content

Conversation

@mohsenpashna
Copy link

@mohsenpashna mohsenpashna commented Jul 8, 2024

Add some Jitter to the Entry's scheduled time. The actual jitter used will be randomly chosen within the range [0, Jitter]. The jitter will always be converted to a positive duration. Plus:

  • AddFuncWithJitter adds a func to the Cron to be run on the given schedule. The spec is parsed using the time zone of this Cron instance as the default. An opaque ID is returned that can be used to later remove it.

  • AddJobWithJitter adds a Job to the Cron to be run on the given schedule with a specified amount of jitter for each invocation. The spec is parsed using the time zone of this Cron instance as the default. An opaque ID is returned that can be used to later remove it.

  • ScheduleWithJitter adds a Job to the Cron to be run on the given schedule with a specified amount of jitter for each invocation. The job is wrapped with the configured Chain.

  • WithTimeCallback uses the provided time function callback for getting the current time.

Jeremy Scott and others added 12 commits January 14, 2022 12:01
[ch11410] - Fork Cron library and allow configuration of timing function
[ch11410] - Fork Cron library and allow configuration of timing function
[ch12701] - Fixed issue where custom time callback was used for first event, but not for subsequent events.
…ehaviour

[GRM-287] - Tasks scheduled by the scheduler seem to either behave erratically or don't run at all.
@alaingilbert
Copy link

@mohsenpashna I made a fork that addresses almost all issues of this repo.
https://github.com/alaingilbert/cron

This is how you could do what you want to do ->

// Jitter adds some random delay before running the job
_, _ = c.AddJob("*/5 * * * *", cron.WithJitter(time.Minute, func() {
	fmt.Println("Runs every 5min, but wait 0-1 minute before starting")
}))

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

Successfully merging this pull request may close these issues.

3 participants