-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[FEATURE REQUEST] random/N for salt.states.cron #60567
Comments
On Fedora 34 Test/etc/crontab
/tmp/crontest
|
Seems like this could be a useful feature. I do wonder how far off of upstream cron implementations we'd be headed. I know some cron implementations have the ability to add random delay to jobs. Adding support for this might accomplish what you are after. |
@leeclemens Thanks for looking into that. I think it might work to do @dwoz Makes sense, and thanks, I'll look at some other cron implementations. |
@dseomn having salt extrapolate those combinations would be my next thought based on what I've seen. May get a little cumbersome, so perhaps there's a more elegant solution. I saw some notations like |
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_filters.html#random-items-or-numbers has another idea for how to implement this. I haven't tested this yet, but I think using https://docs.saltproject.io/en/latest/ref/modules/all/salt.modules.mod_random.html#salt.modules.mod_random.rand_int could work something like:
|
With the cron.present and cron.absent states, it's possible to remove old/unexpected cron jobs, but it requires a bunch of manual checking for them. Those checks use execution modules, which are really slow in salt-ssh. This avoids that by accumulating lines in one file, so when a cron job state is removed, the next update of that file won't have the old line. Also, this makes it relatively easy to implement saltstack/salt#60567 while I'm at it.
Describe the solution you'd like
salt.states.cron currently supports values like
minute: '*/5'
to run every 5 minutes. If I understand correctly, that runs on minutes 0, 5, 10, etc., right? There's also support forminute: 'random'
to run on a random minute. It would be nice to have the combination of those two features so something likeminute: 'random/5'
would run every 5 minutes, starting on a random minute between 0 and 4.Describe alternatives you've considered
I'm not aware of any other easy way to spread out cron jobs that run every N minutes/hours/etc. It is possible for a cron job to
sleep
for a random amount of time before doing anything else though.The text was updated successfully, but these errors were encountered: