Skip to content

Commit

Permalink
clarify some names
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Apr 4, 2024
1 parent 5a2b2f6 commit f4c3171
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions backend/controller/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type jobChangeType int
const (
resetJobs jobChangeType = iota
createJobs
updateJobs
finishedJobs
removedDeploymentKey
updatedHashring
)
Expand Down Expand Up @@ -183,7 +183,7 @@ func (s *Service) executeJob(ctx context.Context, job dal.CronJob) {
logger.Errorf(err, "failed to end cronjob %v:%v", job.DeploymentKey, job.Verb)
} else {
s.jobChanges.Publish(jobChange{
changeType: updateJobs,
changeType: finishedJobs,
jobs: []dal.CronJob{updatedJob},
})
}
Expand Down Expand Up @@ -217,7 +217,7 @@ func (s *Service) watchForUpdates(ctx context.Context) {
now := s.clock.Now()
next := time.Now().Add(time.Hour) // should never be reached, expect a different signal long beforehand
for _, j := range state.jobs {
if possibleNext, err := s.nextCheckForJob(j, state, false); err == nil {
if possibleNext, err := s.nextAttemptForJob(j, state, false); err == nil {
next = *possibleNext
break
}
Expand All @@ -238,7 +238,7 @@ func (s *Service) watchForUpdates(ctx context.Context) {
case <-s.clock.After(next.Sub(now)):
// Try starting jobs in db
jobsToAttempt := slices.Filter(state.jobs, func(j dal.CronJob) bool {
if next, err := s.nextCheckForJob(j, state, true); err == nil {
if next, err := s.nextAttemptForJob(j, state, true); err == nil {
return !next.After(time.Now().UTC())
}
return false
Expand Down Expand Up @@ -284,7 +284,7 @@ func (s *Service) watchForUpdates(ctx context.Context) {
case createJobs:
logger.Tracef("adding %d jobs", len(event.jobs))
state.addJobs(event.jobs)
case updateJobs:
case finishedJobs:
logger.Tracef("updating %d jobs", len(event.jobs))
state.updateJobs(event.jobs)
case removedDeploymentKey:
Expand All @@ -298,18 +298,18 @@ func (s *Service) watchForUpdates(ctx context.Context) {
}

func (s *Service) sortJobs(state *State, i, j dal.CronJob) int {
iNext, err := s.nextCheckForJob(i, state, false)
iNext, err := s.nextAttemptForJob(i, state, false)
if err != nil {
return 1
}
jNext, err := s.nextCheckForJob(j, state, false)
jNext, err := s.nextAttemptForJob(j, state, false)
if err != nil {
return -1
}
return iNext.Compare(*jNext)
}

func (s *Service) nextCheckForJob(job dal.CronJob, state *State, allowsNow bool) (*time.Time, error) {
func (s *Service) nextAttemptForJob(job dal.CronJob, state *State, allowsNow bool) (*time.Time, error) {
if !s.isResponsibleForJob(job, state) {
return nil, fmt.Errorf("controller is not responsible for job")
}
Expand Down

0 comments on commit f4c3171

Please sign in to comment.