From af31592cdd4c3feb0a988d2a6fc09227160cb40f Mon Sep 17 00:00:00 2001 From: Chris Martin Date: Fri, 6 Sep 2024 09:29:54 +0100 Subject: [PATCH] Filter out invalid JST in ReconcileDifferences (#3911) * Filter out invalid JST in ReconcileDifferences (#221) * lint Signed-off-by: Chris Martin --------- Signed-off-by: Chris Martin Co-authored-by: Christopher Martin --- internal/scheduler/jobdb/reconciliation.go | 12 +++++++++--- internal/scheduler/scheduler.go | 6 +----- 2 files changed, 10 insertions(+), 8 deletions(-) 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