Skip to content

Commit

Permalink
chore: do not record canary sync successes to job history (#1245)
Browse files Browse the repository at this point in the history
* chore: do not record canary sync successes to job history

* chore: remove time.Sleep and add more context to error log
  • Loading branch information
adityathebe authored Sep 1, 2023
1 parent e730de0 commit 11cbba8
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions pkg/jobs/canary/canary_jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,23 +347,24 @@ func SyncCanaryJobs() {
canaries, err := db.GetAllCanariesForSync()
if err != nil {
logger.Errorf("Failed to get canaries: %v", err)

jobHistory := models.NewJobHistory("SyncCanaries", "canary", "").Start()
logIfError(db.PersistJobHistory(jobHistory.AddError(err.Error()).End()), "failed to persist job history [SyncCanaries]")

return
}

existingIDsInCron := getAllCanaryIDsInCron()
var idsInNewFetch []string
idsInNewFetch := make([]string, 0, len(canaries))
for _, c := range canaries {
jobHistory := models.NewJobHistory("CanarySync", "canary", c.ID.String()).Start()
_ = db.PersistJobHistory(jobHistory)

idsInNewFetch = append(idsInNewFetch, c.ID.String())
if err := SyncCanaryJob(c); err != nil {
logger.Errorf("Error syncing canary[%s]: %v", c.ID, err.Error())
_ = db.PersistJobHistory(jobHistory.AddError(err.Error()).End())
logIfError(db.PersistJobHistory(jobHistory.AddError(err.Error()).End()), "failed to persist job history [CanarySync]")
continue
}
jobHistory.IncrSuccess()
_ = db.PersistJobHistory(jobHistory.End())
}

idsToRemoveFromCron := utils.SetDifference(existingIDsInCron, idsInNewFetch)
Expand All @@ -385,9 +386,12 @@ func DeleteCanaryJob(id string) {

func ReconcileCanaryChecks() {
logger.Infof("Reconciling Canary Checks")

jobHistory := models.NewJobHistory("ReconcileCanaryChecks", "", "").Start()
_ = db.PersistJobHistory(jobHistory)
defer func() { _ = db.PersistJobHistory(jobHistory.End()) }()
logIfError(db.PersistJobHistory(jobHistory), "failed to persist job history [ReconcileCanaryChecks start]")
defer func() {
logIfError(db.PersistJobHistory(jobHistory.End()), "failed to persist job history [ReconcileCanaryChecks end]")
}()

canaries, err := db.GetAllCanariesForSync()
if err != nil {
Expand Down Expand Up @@ -448,3 +452,9 @@ func init() {
// We are adding a small buffer to prevent blocking
CanaryStatusChannel = make(chan CanaryStatusPayload, 64)
}

func logIfError(err error, description string) {
if err != nil {
logger.Errorf("%s: %v", description, err)
}
}

0 comments on commit 11cbba8

Please sign in to comment.