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

Showcase how to randomize cron schedules #96

Closed
corvus-ch opened this issue Oct 14, 2020 · 2 comments · Fixed by #97
Closed

Showcase how to randomize cron schedules #96

corvus-ch opened this issue Oct 14, 2020 · 2 comments · Fixed by #97
Assignees
Labels
enhancement New feature or request

Comments

@corvus-ch
Copy link
Contributor

corvus-ch commented Oct 14, 2020

Randomize CronJob or any other time based schedules is a crucial topic.

Example:

local scope = "…" // Something that defines the scope of the schedule
local minute = std.foldl(function(x, y) x + y, std.encodeUTF8(std.md5(scope)), 0) % 60;
local job = kube.CronJob(name) {
  spec+: {
    schedule: '%d * * * *' % minute,
  …
}

Using a hash function makes the result deterministic. For that reason, the scope becomes important to ensure distribution of values.

Suggestions:

  • For things running on clusters but act against a common system, use the cluster name. This will ensure, that all those jobs are executed at a different time.
  • For things running on the same cluster but should be spread over time, use something like the namespace and or job name the job is running in. The same job will run at the same time on every cluster but different jobs on a cluster will run a different times
  • Mixing in the the clusters name with namespace and or job names will ensure that different jobs run at different times both on the same cluster as well as the whole fleet of clusters.

See also appuio/component-openshift4-authentication@bfbff9d

@corvus-ch corvus-ch added the enhancement New feature or request label Oct 14, 2020
@corvus-ch
Copy link
Contributor Author

corvus-ch commented Oct 15, 2020

This is probably a sub task of #46.

@corvus-ch
Copy link
Contributor Author

Alternatively, we could implement this within some sort of helper/library function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant