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

feat(controller): Use deterministic name for cron workflow children #4638

Merged
merged 11 commits into from
Dec 9, 2020
17 changes: 16 additions & 1 deletion workflow/cron/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,22 @@ func (cc *Controller) Run(ctx context.Context) {
defer cc.cron.Stop()

go cc.cronWfInformer.Informer().Run(ctx.Done())
go wait.Until(cc.syncAll, 10*time.Second, ctx.Done())
go func() {
// To minimize syncAll and scheduled crons stepping over each other, ensure that syncAll runs every 10 seconds
// starting on a x5 second mark (e.g., 15, 35, etc.). Since crons are guaranteed to run on a 00 second mark, this
// makes sure that there is always a 5 second time separation between syncAll opeartions and any scheduled cron
_, _, sec := time.Now().Clock()
singleSec := sec % 10
var toWait time.Duration
if singleSec <= 5 {
toWait = time.Duration(5-singleSec) * time.Second
alexec marked this conversation as resolved.
Show resolved Hide resolved
} else {
toWait = time.Duration(15-singleSec) * time.Second
}
time.Sleep(toWait)

go wait.NonSlidingUntil(cc.syncAll, 10*time.Second, ctx.Done())
}()

for i := 0; i < cronWorkflowWorkers; i++ {
go wait.Until(cc.runCronWorker, time.Second, ctx.Done())
Expand Down