saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.03k stars 5.47k forks source link

[FEATURE REQUEST] Support hashed expressions in cron schedules #65549

Open OrangeDog opened 8 months ago

OrangeDog commented 8 months ago

Is your feature request related to a problem? Please describe. When you want to run a schedule periodically, independent of the service start time, but not have minions all fire at the same time.

Describe the solution you'd like Being able to supply "Jenkins-style" hashed expressions in the cron specification.

A basic implementation could supply the minion id as the hash_id for every usage of cron. However, allowing the user to provide their own cron_hash may be preferable, especially as the presence of hash_id affects the meaning of keywords (e.g. @weekly).

It could detect an H in the input and provide a fallback hash if one is not set to make things easier.

Describe alternatives you've considered splay provides similar functionality, but does not give a consistent period and does not work with cron specifications.

Additional context Requires croniter >= 1.0.12

dseomn commented 2 months ago

If there is a default hash_id, I think it would work better if it included the minion id and also the values of the user and identifier args to cron.present. That way if the same minion has multiple jobs running at H H * * *, they won't all start at the same time.

Btw, I think I found a somewhat hacky way to implement this in jinja in https://github.com/saltstack/salt/issues/60567#issuecomment-2105995223, but native support would be nicer.