|
|
|
|
|
by parliament32
2220 days ago
|
|
Unfortunately, it's still missing the main cron-killer feature: randomized intervals. I have 200 servers that I need to run some task every 3 hours. But I don't want them to all run at the same time. I need options to either "start this task at some point randomly in the next 3 hours, then every 3 hours thereafter" or "run this task randomly in every 3 hour block", without resorting to manually tweaking hour/minute run times on every server. |
|
Find a value that is unique to each server (e.g. the UUID of the / partition?) to seed your PRNG, and then generate the first pseudo-random number. If you do it right, it will always be the same number.
Modulo this number against the number of (seconds|minutes|hours) of random delay you want applied, and apply a sleep timer to the start of the job based on that result.
It's dirty, but it ensures
* each server gets its own random interval from the start time
* that random interval never changes
* the server runs the job on a regular schedule
There are probably better ways of doing this, but this is the first thing I could think of that doesn't require any crazy libraries and can be done using standard linux utils that are on all machines.
I'd love to hear any better ways that people have!