Skip to content

Commit

Permalink
Filter out invalid JST in ReconcileDifferences (#3911)
Browse files Browse the repository at this point in the history
* Filter out invalid JST in ReconcileDifferences (#221)

* lint

Signed-off-by: Chris Martin <chris@cmartinit.co.uk>

---------

Signed-off-by: Chris Martin <chris@cmartinit.co.uk>
Co-authored-by: Christopher Martin <Chris.Martin@gresearch.co.uk>
  • Loading branch information
d80tb7 and svc-oeg-aws2github authored Sep 6, 2024
1 parent 0e7307c commit af31592
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 9 additions & 3 deletions internal/scheduler/jobdb/reconciliation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
6 changes: 1 addition & 5 deletions internal/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit af31592

Please sign in to comment.