diff --git a/pkg/cache/postgres.go b/pkg/cache/postgres.go index 5560fa308..f49bbbfba 100644 --- a/pkg/cache/postgres.go +++ b/pkg/cache/postgres.go @@ -28,7 +28,7 @@ func NewPostgresCache(pool *pgxpool.Pool) *postgresCache { } func (c *postgresCache) Add(check pkg.Check, statii ...pkg.CheckStatus) []string { - var checkIDs = make([]string, 0, len(statii)) + checkIDs := make([]string, 0, len(statii)) for _, status := range statii { if status.Status { diff --git a/pkg/jobs/canary/sync_upstream.go b/pkg/jobs/canary/sync_upstream.go index 5c0fb20ab..cedfb26be 100644 --- a/pkg/jobs/canary/sync_upstream.go +++ b/pkg/jobs/canary/sync_upstream.go @@ -22,12 +22,12 @@ var tablesToReconcile = []string{ "check_statuses", } -// SyncWithUpstream coordinates with upstream and pushes any resource +// PushCanaryResultsToUpstream coordinates with upstream and pushes any resource // that are missing on the upstream. -func SyncWithUpstream() { +func PushCanaryResultsToUpstream() { ctx := context.New(nil, nil, db.Gorm, v1.Canary{}) - jobHistory := models.NewJobHistory("SyncCanaryResultsWithUpstream", "Canary", "") + jobHistory := models.NewJobHistory("PushCanaryResultsToUpstream", "Canary", "") _ = db.PersistJobHistory(jobHistory.Start()) defer func() { _ = db.PersistJobHistory(jobHistory.End()) }() @@ -43,16 +43,16 @@ func SyncWithUpstream() { } func Pull() { - jobHistory := models.NewJobHistory("PullAgentCanaries", "Canary", "") + jobHistory := models.NewJobHistory("PullUpstreamCanaries", "Canary", "") _ = db.PersistJobHistory(jobHistory.Start()) defer func() { _ = db.PersistJobHistory(jobHistory.End()) }() if err := pull(UpstreamConf); err != nil { jobHistory.AddError(err.Error()) logger.Errorf("Error pulling upstream: %v", err) + } else { + jobHistory.IncrSuccess() } - - jobHistory.IncrSuccess() } func pull(config upstream.UpstreamConfig) error { @@ -63,7 +63,7 @@ func pull(config upstream.UpstreamConfig) error { req, err := http.NewRequest(http.MethodGet, endpoint, nil) if err != nil { - return err + return fmt.Errorf("error creating new http request: %w", err) } req.SetBasicAuth(config.Username, config.Password) diff --git a/pkg/jobs/jobs.go b/pkg/jobs/jobs.go index 5edccb0db..e09c50f3d 100644 --- a/pkg/jobs/jobs.go +++ b/pkg/jobs/jobs.go @@ -14,6 +14,8 @@ import ( var FuncScheduler = cron.New() const ( + PullCanaryFromUpstreamSchedule = "@every 2m" + PushCanaryToUpstreamSchedule = "@every 5m" SyncCanaryJobsSchedule = "@every 2m" SyncSystemsJobsSchedule = "@every 5m" ComponentRunSchedule = "@every 2m" @@ -42,13 +44,13 @@ func Start() { if canaryJobs.UpstreamConf.Valid() { canaryJobs.Pull() - canaryJobs.SyncWithUpstream() + canaryJobs.PushCanaryResultsToUpstream() - if _, err := ScheduleFunc(SyncCanaryJobsSchedule, canaryJobs.Pull); err != nil { + if _, err := ScheduleFunc(PullCanaryFromUpstreamSchedule, canaryJobs.Pull); err != nil { logger.Errorf("Failed to schedule job [canaryJobs.Pull]: %v", err) } - if _, err := ScheduleFunc(SyncCanaryJobsSchedule, canaryJobs.SyncWithUpstream); err != nil { + if _, err := ScheduleFunc(PushCanaryToUpstreamSchedule, canaryJobs.PushCanaryResultsToUpstream); err != nil { logger.Errorf("Failed to schedule job [canaryJobs.SyncWithUpstream]: %v", err) } }