-
Notifications
You must be signed in to change notification settings - Fork 32
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
fix: cron flow for canaries #1109
Changes from 2 commits
3ca14ab
590de90
ee1410e
94d765a
d9d7db8
d800d9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -242,8 +242,11 @@ func ScanCanaryConfigs() { | |
} | ||
} | ||
|
||
var canaryUpdateTimeCache = make(map[string]time.Time) | ||
|
||
// TODO: Refactor to use database object instead of kubernetes | ||
func SyncCanaryJob(canary v1.Canary) error { | ||
if !canary.DeletionTimestamp.IsZero() || canary.Spec.GetSchedule() == "@never" { //nolint:goconst | ||
if !canary.DeletionTimestamp.IsZero() || canary.Spec.GetSchedule() == "@never" { | ||
DeleteCanaryJob(canary) | ||
return nil | ||
} | ||
|
@@ -256,9 +259,9 @@ func SyncCanaryJob(canary v1.Canary) error { | |
} | ||
} | ||
|
||
entry := findCronEntry(canary) | ||
if entry != nil { | ||
CanaryScheduler.Remove(entry.ID) | ||
dbCanary, err := db.GetCanary(canary.GetPersistedID()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
job := CanaryJob{ | ||
|
@@ -269,15 +272,26 @@ func SyncCanaryJob(canary v1.Canary) error { | |
LogFail: canary.IsTrace() || canary.IsDebug() || LogFail, | ||
} | ||
|
||
_, err := CanaryScheduler.AddJob(canary.Spec.GetSchedule(), job) | ||
if err != nil { | ||
return fmt.Errorf("failed to schedule canary %s/%s: %v", canary.Namespace, canary.Name, err) | ||
updateTime, exists := canaryUpdateTimeCache[dbCanary.ID.String()] | ||
entry := findCronEntry(canary) | ||
if !exists || dbCanary.UpdatedAt.After(updateTime) || entry == nil { | ||
// Remove entry if it exists | ||
if entry != nil { | ||
CanaryScheduler.Remove(entry.ID) | ||
} | ||
|
||
// Schedule canary for the first time | ||
_, err = CanaryScheduler.AddJob(canary.Spec.GetSchedule(), job) | ||
if err != nil { | ||
return fmt.Errorf("failed to schedule canary %s/%s: %v", canary.Namespace, canary.Name, err) | ||
} | ||
logger.Infof("Scheduled %s: %s", canary, canary.Spec.GetSchedule()) | ||
|
||
canaryUpdateTimeCache[dbCanary.ID.String()] = dbCanary.UpdatedAt | ||
} | ||
logger.Infof("Scheduled %s: %s", canary, canary.Spec.GetSchedule()) | ||
|
||
entry = findCronEntry(canary) | ||
if entry != nil && time.Until(entry.Next) < 1*time.Hour { | ||
// run all regular canaries on startup | ||
//Run all regularly scheduled canaries on startup (<1h) and not daily/weekly schedules | ||
if entry != nil && time.Until(entry.Next) < 1*time.Hour && !exists { | ||
job = entry.Job.(CanaryJob) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this line? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, from a ux perspective if I add a check that runs every 15 minutes I don't want to wait for 15m to see if it worked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @moshloop I meant just this one line
|
||
go job.Run() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this condition ever satisfied? If the cron entry is not nil, then the update time will also exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have updated the code to modify entry