From 1fc0bf9dd06e46ab47a51c8173f6fa72f3e77bce Mon Sep 17 00:00:00 2001 From: Mohsin Zaidi <2236875+smrz2001@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:45:22 -0400 Subject: [PATCH] chore(cd): editorial cleanup --- cd/manager/jobmanager/jobManager.go | 36 ++++++++++++++--------------- cd/manager/jobs/anchor.go | 4 ++-- cd/manager/jobs/deploy.go | 4 ++-- cd/manager/jobs/e2e.go | 4 ++-- cd/manager/jobs/smoke.go | 4 ++-- cd/manager/models.go | 4 ++-- 6 files changed, 28 insertions(+), 28 deletions(-) diff --git a/cd/manager/jobmanager/jobManager.go b/cd/manager/jobmanager/jobManager.go index ce06727..196c0b0 100644 --- a/cd/manager/jobmanager/jobManager.go +++ b/cd/manager/jobmanager/jobManager.go @@ -68,8 +68,8 @@ func (m *JobManager) NewJob(jobState job.JobState) (string, error) { } func (m *JobManager) CheckJob(jobId string) string { - if job, found := m.cache.JobById(jobId); found { - return string(job.Stage) + if cachedJob, found := m.cache.JobById(jobId); found { + return string(cachedJob.Stage) } return "" } @@ -120,18 +120,18 @@ func (m *JobManager) processJobs() { }) if len(oldJobs) > 0 { log.Printf("processJobs: aging out %d jobs...", len(oldJobs)) - for _, job := range oldJobs { + for _, oldJob := range oldJobs { // Delete the job from the cache - log.Printf("processJobs: aging out job: %s", manager.PrintJob(job)) - m.cache.DeleteJob(job.Job) + log.Printf("processJobs: aging out job: %s", manager.PrintJob(oldJob)) + m.cache.DeleteJob(oldJob.Job) } } // Find all jobs in progress and advance their state before looking for new jobs activeJobs := m.cache.JobsByMatcher(job.IsActiveJob) if len(activeJobs) > 0 { log.Printf("processJobs: checking %d jobs in progress: %s", len(activeJobs), manager.PrintJob(activeJobs...)) - for _, job := range activeJobs { - m.advanceJob(job) + for _, activeJob := range activeJobs { + m.advanceJob(activeJob) } } // Wait for any running job advancement goroutines to finish before kicking off more jobs @@ -446,9 +446,9 @@ func (m *JobManager) advanceJob(jobState job.JobState) { }() currentJobStage := jobState.Stage - if job, err := m.prepareJob(jobState); err != nil { + if jobSm, err := m.prepareJobSm(jobState); err != nil { log.Printf("advanceJob: job generation failed: %v, %s", err, manager.PrintJob(jobState)) - } else if newJobState, err := job.Advance(); err != nil { + } else if newJobState, err := jobSm.Advance(); err != nil { // Advancing should automatically update the cache and database in case of failures log.Printf("advanceJob: job advancement failed: %v, %s", err, manager.PrintJob(jobState)) } else if newJobState.Stage != currentJobStage { @@ -503,27 +503,27 @@ func (m *JobManager) postProcessJob(jobState job.JobState) { } } -func (m *JobManager) prepareJob(jobState job.JobState) (manager.Job, error) { - var j manager.Job +func (m *JobManager) prepareJobSm(jobState job.JobState) (manager.JobSm, error) { + var jobSm manager.JobSm var err error = nil switch jobState.Type { case job.JobType_Deploy: - j, err = jobs.DeployJob(jobState, m.db, m.notifs, m.d, m.repo) + jobSm, err = jobs.DeployJob(jobState, m.db, m.notifs, m.d, m.repo) case job.JobType_Anchor: - j = jobs.AnchorJob(jobState, m.db, m.notifs, m.d) + jobSm = jobs.AnchorJob(jobState, m.db, m.notifs, m.d) case job.JobType_TestE2E: - j = jobs.E2eTestJob(jobState, m.db, m.notifs, m.d) + jobSm = jobs.E2eTestJob(jobState, m.db, m.notifs, m.d) case job.JobType_TestSmoke: - j = jobs.SmokeTestJob(jobState, m.db, m.notifs, m.d) + jobSm = jobs.SmokeTestJob(jobState, m.db, m.notifs, m.d) default: - err = fmt.Errorf("prepareJob: unknown job type: %s", manager.PrintJob(jobState)) + err = fmt.Errorf("prepareJobSm: unknown job type: %s", manager.PrintJob(jobState)) } if err != nil { if err := m.updateJobStage(jobState, job.JobStage_Failed, err); err != nil { - log.Printf("prepareJob: job update failed: %v, %s", err, manager.PrintJob(jobState)) + log.Printf("prepareJobSm: job update failed: %v, %s", err, manager.PrintJob(jobState)) } } - return j, err + return jobSm, err } func (m *JobManager) updateJobStage(jobState job.JobState, jobStage job.JobStage, e error) error { diff --git a/cd/manager/jobs/anchor.go b/cd/manager/jobs/anchor.go index b88dbe0..e5fc494 100644 --- a/cd/manager/jobs/anchor.go +++ b/cd/manager/jobs/anchor.go @@ -12,7 +12,7 @@ import ( // Allow up to 3 hours for anchor workers to run const AnchorStalledTime = 3 * time.Hour -var _ manager.Job = &anchorJob{} +var _ manager.JobSm = &anchorJob{} type anchorJob struct { baseJob @@ -20,7 +20,7 @@ type anchorJob struct { d manager.Deployment } -func AnchorJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.Job { +func AnchorJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.JobSm { return &anchorJob{baseJob{jobState, db, notifs}, os.Getenv("ENV"), d} } diff --git a/cd/manager/jobs/deploy.go b/cd/manager/jobs/deploy.go index c351514..860956c 100644 --- a/cd/manager/jobs/deploy.go +++ b/cd/manager/jobs/deploy.go @@ -10,7 +10,7 @@ import ( "github.com/3box/pipeline-tools/cd/manager/common/job" ) -var _ manager.Job = &deployJob{} +var _ manager.JobSm = &deployJob{} type deployJob struct { baseJob @@ -22,7 +22,7 @@ type deployJob struct { repo manager.Repository } -func DeployJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment, repo manager.Repository) (manager.Job, error) { +func DeployJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment, repo manager.Repository) (manager.JobSm, error) { if component, found := jobState.Params[job.JobParam_Component].(string); !found { return nil, fmt.Errorf("deployJob: missing component (ceramic, ipfs, cas)") } else if sha, found := jobState.Params[job.JobParam_Sha].(string); !found { diff --git a/cd/manager/jobs/e2e.go b/cd/manager/jobs/e2e.go index 4a3a2ad..03eca02 100644 --- a/cd/manager/jobs/e2e.go +++ b/cd/manager/jobs/e2e.go @@ -12,14 +12,14 @@ import ( // Allow up to 4 hours for E2E tests to run const e2eFailureTime = 4 * time.Hour -var _ manager.Job = &e2eTestJob{} +var _ manager.JobSm = &e2eTestJob{} type e2eTestJob struct { baseJob d manager.Deployment } -func E2eTestJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.Job { +func E2eTestJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.JobSm { return &e2eTestJob{baseJob{jobState, db, notifs}, d} } diff --git a/cd/manager/jobs/smoke.go b/cd/manager/jobs/smoke.go index 661240f..9441897 100644 --- a/cd/manager/jobs/smoke.go +++ b/cd/manager/jobs/smoke.go @@ -17,7 +17,7 @@ const FamilyPrefix = "ceramic-qa-tests-smoke--" const ContainerName = "ceramic-qa-tests-smoke" const NetworkConfigurationParameter = "/ceramic-qa-tests-smoke/network_configuration" -var _ manager.Job = &smokeTestJob{} +var _ manager.JobSm = &smokeTestJob{} type smokeTestJob struct { baseJob @@ -25,7 +25,7 @@ type smokeTestJob struct { d manager.Deployment } -func SmokeTestJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.Job { +func SmokeTestJob(jobState job.JobState, db manager.Database, notifs manager.Notifs, d manager.Deployment) manager.JobSm { return &smokeTestJob{baseJob{jobState, db, notifs}, os.Getenv("ENV"), d} } diff --git a/cd/manager/models.go b/cd/manager/models.go index e882d72..1949f8f 100644 --- a/cd/manager/models.go +++ b/cd/manager/models.go @@ -156,8 +156,8 @@ type Task struct { Name string `dynamodbav:"name,omitempty"` // Container name } -// Job represents job state machine objects processed by the job manager -type Job interface { +// JobSm represents job state machine objects processed by the job manager +type JobSm interface { Advance() (job.JobState, error) }