robfig / cron

a cron library for go
MIT License
13.15k stars 1.63k forks source link

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

Open adampetrovic opened 1 month ago

adampetrovic commented 1 month ago

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:

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 commented 1 month ago

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

tooptoop4 commented 1 month ago

dis abandonware ☠️