diff --git a/internal/scheduler/jobdb/reconciliation.go b/internal/scheduler/jobdb/reconciliation.go index d76bc64401d..8513feae9cf 100644 --- a/internal/scheduler/jobdb/reconciliation.go +++ b/internal/scheduler/jobdb/reconciliation.go @@ -78,13 +78,19 @@ func (jobDb *JobDb) ReconcileDifferences(txn *Txn, jobRepoJobs []database.Job, j jsts := make([]JobStateTransitions, 0, len(jobRepoJobsById)) for jobId, jobRepoJob := range jobRepoJobsById { - if jst, err := jobDb.reconcileJobDifferences( + jst, err := jobDb.reconcileJobDifferences( txn.GetById(jobId), // Existing job in the jobDb. jobRepoJob, // New or updated job from the jobRepo. jobRepoRunsById[jobId], // New or updated runs associated with this job from the jobRepo. - ); err != nil { + ) + if err != nil { return nil, err - } else { + } + + // We receive nil jobs from jobDb.ReconcileDifferences if a run is updated after the associated job is deleted. + // In this case it is safe to ignore the jst. + // TODO: don't generate a jst in the first place if this is the case! + if jst.Job != nil { jsts = append(jsts, jst) } } diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go index 446d603b83d..1a8301864e9 100644 --- a/internal/scheduler/scheduler.go +++ b/internal/scheduler/scheduler.go @@ -373,11 +373,7 @@ func (s *Scheduler) syncState(ctx *armadacontext.Context) ([]*jobdb.Job, []jobdb // Upsert updated jobs (including associated runs). jobDbJobs := make([]*jobdb.Job, 0, len(jsts)) for _, jst := range jsts { - if jst.Job != nil { - // We receive nil jobs from jobDb.ReconcileDifferences if a run is updated after the associated job is deleted. - // These nil job must be sorted out. - jobDbJobs = append(jobDbJobs, jst.Job) - } + jobDbJobs = append(jobDbJobs, jst.Job) } if err := txn.Upsert(jobDbJobs); err != nil { return nil, nil, err