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

#309: Support Jenkins-style Hash expressions for pseudo-randomness #531

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

adampetrovic
Copy link

@adampetrovic adampetrovic commented Oct 22, 2024

This implements what is requested in #309

Some cron implementations use H as a hashed substitution for a value:

'H' is used in the Jenkins continuous integration system to indicate that a "hashed" value is substituted. Thus instead of a fixed number such as '20 * * * *' which means at 20 minutes after the hour every hour, 'H * * * *' indicates that the task is performed every hour at an unspecified but invariant time for each task. This allows spreading out tasks over time, rather than having all of them start at the same time and compete for resources.

This change extends the API without breaking backward compatibility by adding a ParseWithJobName function allowing the caller to provide a unique job name to perform the hashing.

The function supports the following expressions:

  • H: Uses the provided bounds as min/max with step of 1
  • H/n: Uses the provided bounds as min/max with step of n
  • H(min-max): Uses the specified range with step of 1
  • H(min-max)/n: Uses the specified range with step of n
parser := NewParser(SecondOptional | Minute | Hour | Dom | Month | Dow | Descriptor)
parser.ParseWithJobName("H(0-30)/10 * * * * *", "job2")
// results in a schedule that runs every minute at the 8, 18, 28 second mark.

@adampetrovic
Copy link
Author

@robfig any chance you're still accepting PRs on this project? It seems there hasn't been a commit in 4 years.

@tooptoop4
Copy link

dis abandonware ☠️

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.

2 participants