Open ebiiim opened 1 year ago
Problem
Collection currently increments cron, but actually it's difficult to define "increment" for cron.
Collection
$ kubectl get cronjobs NAME SCHEDULE SUSPEND ACTIVE LAST SCHEDULE AGE gitbackup-coll1-bar 2 6 * * * False 0 <none> 5s gitbackup-coll1-foo 1 6 * * * False 0 <none> 5s gitbackup-coll1-gitbackup 0 6 * * * False 0 <none> 5s
Proposal
Inserting a random delay like rand(0, repo_num*10) is a good alternative.
rand(0, repo_num*10)
To allow Collection to set the delay to the controlled Repository, add spec.maxRandomDelay field to Repository.
Repository
spec.maxRandomDelay
apiVersion: gitbackup.ebiiim.com/v1beta1 kind: Repository spec: # max random delay in seconds maxRandomDelay: 60 ...
Random delay can be implemented in shell script like sleep $(shuf -i0-123 -n1) or sleep $(( RANDOM % 123 )).
sleep $(shuf -i0-123 -n1)
sleep $(( RANDOM % 123 ))
Note: $RANDOM returns a number in the range 0 - 32767
$RANDOM
Problem
Collection
currently increments cron, but actually it's difficult to define "increment" for cron.Proposal
Inserting a random delay like
rand(0, repo_num*10)
is a good alternative.To allow
Collection
to set the delay to the controlledRepository
, addspec.maxRandomDelay
field toRepository
.Random delay can be implemented in shell script like
sleep $(shuf -i0-123 -n1)
orsleep $(( RANDOM % 123 ))
.Note:
$RANDOM
returns a number in the range 0 - 32767