Skip to content

Commit

Permalink
Fix the issue with missing raws. (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
seilagamo authored Jul 20, 2023
1 parent b360d78 commit 3e38373
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
22 changes: 4 additions & 18 deletions jobrunner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,16 @@ func (im *inMemChecksUpdater) UpdateCheckStatusTerminal(s stateupdater.CheckStat
if im.terminalStatus == nil {
im.terminalStatus = make(map[string]stateupdater.CheckState)
}
checkState, ok := im.terminalStatus[s.ID]
cs, ok := im.terminalStatus[s.ID]
if !ok {
im.terminalStatus[s.ID] = s
return
}

// We update the existing CheckState
if s.Status != nil {
checkState.Status = s.Status
}
if s.Raw != nil {
checkState.Raw = s.Raw
}
if s.AgentID != nil {
checkState.AgentID = s.AgentID
}
if s.Progress != nil {
checkState.Progress = s.Progress
}
if s.Report != nil {
checkState.Report = s.Report
}
// We update the existing CheckState.
cs.Merge(s)

im.terminalStatus[checkState.ID] = checkState
im.terminalStatus[cs.ID] = cs
}

func (im *inMemChecksUpdater) FlushCheckStatus(ID string) error {
Expand Down
38 changes: 22 additions & 16 deletions stateupdater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@ type CheckState struct {
Progress *float32 `json:"progress,omitempty"`
}

// Merge overrides the fields of the receiver with the value of the non nil
// fields of the provided CheckState.
func (cs *CheckState) Merge(s CheckState) {
if s.Status != nil {
cs.Status = s.Status
}
if s.Raw != nil {
cs.Raw = s.Raw
}
if s.AgentID != nil {
cs.AgentID = s.AgentID
}
if s.Progress != nil {
cs.Progress = s.Progress
}
if s.Report != nil {
cs.Report = s.Report
}
}

// QueueWriter defines the queue services used by and
// updater to send the status updates.
type QueueWriter interface {
Expand Down Expand Up @@ -132,22 +152,8 @@ func (u *Updater) UpdateCheckStatusTerminal(s CheckState) {
}
cs := checkState.(CheckState)

// We update the existing CheckState
if s.Status != nil {
cs.Status = s.Status
}
if cs.Raw != nil {
cs.Raw = s.Raw
}
if cs.AgentID != nil {
cs.AgentID = s.AgentID
}
if cs.Progress != nil {
cs.Progress = s.Progress
}
if cs.Report != nil {
cs.Report = s.Report
}
// We update the existing CheckState.
cs.Merge(s)

u.terminalChecks.Store(s.ID, cs)
}

0 comments on commit 3e38373

Please sign in to comment.