Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
adityathebe committed Jul 27, 2023
1 parent 98bb5f6 commit 097d158
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/cache/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 7 additions & 7 deletions pkg/jobs/canary/sync_upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }()

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions pkg/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 097d158

Please sign in to comment.