Feature #311
cron random time
| Status: | Closed | Start: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% |
||
| Category: | cron | |||
| Target version: | 0.24.5 | |||
| Affected version: | 0.25.4 | Branch: | ||
| Keywords: | ||||
| Votes: | 0 |
Description
hello,
could be great if the cron type could generate a radom time. So for exemple a cron on 10000 hosts would not be executed at the same time.Something like :
minutes => random
or even more power
minutes => random[10-45] // limit the random to the 10-45 minutes
perhaps this could be a function of puppet in general that could be used anywhere even in other types ?
regards, Ghislain.
History
Updated by Matt Palmer almost 4 years ago
I like this idea. The only dangerous bit is that if the ‘random’ fires every time, you end up with your cron jobs wandering all over the place. If that weren’t a problem, a simple random() function would do the job. As it stands, I think it’ll have to be something Cron-specific, which will only generate a new random number if it’s a new job that’s being created. I’m sure that just specifying ‘random’ would be simple to support, but I don’t know if the ranged version would be quite so easy.
Not volunteering, by the way, just commenting… (grin)
Updated by duaneg - almost 4 years ago
How about seeding the RNG with the host ID (not sure if this is the correct terminology, sorry)? That way it would be different for every host but consistent and reproducible on each one.
Updated by Ben - over 3 years ago
For some time i have used this method of achieving this and now i use it when setting up cron job with puppet.
cron { "Example_cron":
command => 'sleep $((RANDOM\%300)) ; /path/to/command',
minute => 20,
user => root
}
This example executes “/path/to/command” at a random second between 0-300 seconds (5 mins).
Updated by ben potts over 2 years ago
Here’s a simple patch for 0.24.4 that adds a fqdn_rand() function to parser/functions.rb.
The function returns a pseudorandom integer based on the FQDN. The first argument determines the max. The second argument is optional and when used, is added to the seed generated from the fqdn.
Updated by James Turnbull over 2 years ago
- Status changed from 1 to Closed
- 7 set to fixed
Pushed in commit [d54338f8921b4b2973dcde52576d7e9fa58148cb] in branch 0.24.x