Skip to content

Commit

Permalink
chore(cd): editorial cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
smrz2001 committed Oct 26, 2023
1 parent 939527d commit 1fc0bf9
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
36 changes: 18 additions & 18 deletions cd/manager/jobmanager/jobManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cd/manager/jobs/anchor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ 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
env string
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}
}

Expand Down
4 changes: 2 additions & 2 deletions cd/manager/jobs/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cd/manager/jobs/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}

Expand Down
4 changes: 2 additions & 2 deletions cd/manager/jobs/smoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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
env string
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}
}

Expand Down
4 changes: 2 additions & 2 deletions cd/manager/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 1fc0bf9

Please sign in to comment.