Skip to content

Commit

Permalink
Fix determining whether a job is edited
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed May 17, 2016
1 parent c37e48e commit 320a5cb
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions nomad/structs/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@ func (j *Job) Diff(other *Job, contextual bool) (*JobDiff, error) {
oldPrimitiveFlat = flatmap.Flatten(j, filter, true)
diff.ID = j.ID
} else {
if !reflect.DeepEqual(j, other) {
diff.Type = DiffTypeEdited
}

if j.ID != other.ID {
return nil, fmt.Errorf("can not diff jobs with different IDs: %q and %q", j.ID, other.ID)
}
Expand Down Expand Up @@ -130,6 +126,20 @@ func (j *Job) Diff(other *Job, contextual bool) (*JobDiff, error) {
diff.Objects = append(diff.Objects, pDiff)
}

// If the job is not a delete or add, determine if there are edits.
if diff.Type == DiffTypeNone {
tgEdit := false
for _, tg := range diff.TaskGroups {
if tg.Type != DiffTypeNone {
tgEdit = true
break
}
}
if tgEdit || len(diff.Fields)+len(diff.Objects) != 0 {
diff.Type = DiffTypeEdited
}
}

return diff, nil
}

Expand Down

0 comments on commit 320a5cb

Please sign in to comment.