projectsyn / documentation

The Project Syn main documentation repository
https://docs.syn.tools/
BSD 3-Clause "New" or "Revised" License
6 stars 3 forks source link

Showcase how to randomize cron schedules #96

Closed corvus-ch closed 3 years ago

corvus-ch commented 3 years ago

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:

See also https://github.com/appuio/component-openshift4-authentication/commit/bfbff9dfb1252bf7753a60da3581bf29a727b619

corvus-ch commented 3 years ago

This is probably a sub task of #46.

corvus-ch commented 3 years ago

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