Skip to content
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

Add randomness to execution time #854

Open
mwgamble opened this issue Feb 15, 2024 · 3 comments
Open

Add randomness to execution time #854

mwgamble opened this issue Feb 15, 2024 · 3 comments
Labels
type:feature New feature or feature improvement & requests

Comments

@mwgamble
Copy link

⭐ Suggestion

The RandomizedDelaySec option for systemd timers: https://www.freedesktop.org/software/systemd/man/latest/systemd.timer.html#RandomizedDelaySec=

💻 Use Cases

We have a job that needs to run once a day. We have several instances of this job running across multiple containers, and we'd like to spread the jobs out a bit. The jobs are all scheduled to run at (for the sake of an example) 8pm, but they don't actually all need to run at 8pm, they just need to run at around that time. It would be nice if we could configure a window of time (say 5-10 minutes) around which the job could run, so that they wouldn't all fire at once. This would help us avoid hitting some rate limits with a third-party API.

❌ Related Problems

We're hitting rate limits on a third-party API because we're doing too much simultaneously across all of the application's containers.

@mwgamble mwgamble added the type:feature New feature or feature improvement & requests label Feb 15, 2024
@sheerlox
Copy link
Collaborator

sheerlox commented Apr 7, 2024

Hey @mwgamble, sorry for the delay. That would be a great addition to cron, and we would gladly entertain a PR if you'd be willing to work on it! Don't hesitate to reach out if you need any help in the process.

@Sho-ki
Copy link

Sho-ki commented Apr 22, 2024

I've developed an npm package that fulfills this purpose:
https://github.com/Sho-ki/random-cron-generator
npm: https://www.npmjs.com/package/random-cron-generator

This implementation is not yet comprehensive, as it does not support all types of cron strings but should meet basic needs.

To maintain the clarity and focus of this repository, I have chosen not to include this feature in this repository. Creating random values can be complex, especially when accounting for the varying number of days in each month.

However, I am open to contributing to this area of the project updates if there is sufficient interest or need.

@sheerlox
Copy link
Collaborator

Hi @Sho-ki, thanks for the suggestion.

However, our goal with cron is to depend as little as possible on other packages.

Moreover, the objective of this feature request is to make the execution time vary from one execution to another, not to mutate the cron expression, which would cover fewer use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:feature New feature or feature improvement & requests
Projects
None yet
Development

No branches or pull requests

3 participants