Skip to content

Commit

Permalink
FS-963 Fix duplicate message publish on success (#169)
Browse files Browse the repository at this point in the history
* Fix an issue where duplicate "success" messages for firmware inventory are showing up in Slack.
* Fix lint issue G601
  • Loading branch information
coffeefreak101 authored Oct 19, 2023
1 parent 40ccf48 commit b42b759
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
12 changes: 10 additions & 2 deletions internal/store/serverservice/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -1167,15 +1167,23 @@ func (r *Store) enrichFirmwareData(deviceVendor, componentVendor string, vattr *
// Check in the cache if we have a match by vendor + version
for _, fw := range r.firmwares[componentVendor] {
if strings.EqualFold(fw.Version, vattr.Firmware.Installed) {
fwUUID := fw.UUID

vattr.Vendor = fw.Vendor
vattr.UUID = &fw.UUID
vattr.UUID = &fwUUID

return
}
}

for _, fw := range r.firmwares[deviceVendor] {
if strings.EqualFold(fw.Version, vattr.Firmware.Installed) {
fwUUID := fw.UUID

vattr.Vendor = fw.Vendor
vattr.UUID = &fw.UUID
vattr.UUID = &fwUUID

return
}
}
}
11 changes: 3 additions & 8 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,6 @@ func (w *Worker) doWork(ctx context.Context, condition *rctypes.Condition, e eve
task.SetState(rctypes.Succeeded)
task.Status = "collection completed successfully"

publisher.Publish(ctx, task)

w.eventAckComplete(e)

metrics.RegisterConditionMetrics(startTS, string(rctypes.Succeeded))
Expand All @@ -332,8 +330,6 @@ func (w *Worker) doWork(ctx context.Context, condition *rctypes.Condition, e eve
nil,
)

publisher.Publish(ctx, task)

w.logger.WithFields(logrus.Fields{
"serverID": task.Parameters.AssetID.String(),
"conditionID": task.ID,
Expand All @@ -349,8 +345,6 @@ func (w *Worker) doWork(ctx context.Context, condition *rctypes.Condition, e eve

w.eventNak(e) // have the message bus re-deliver the message

publisher.Publish(ctx, task)

metrics.RegisterEventCounter(true, "nack")
metrics.RegisterConditionMetrics(startTS, string(rctypes.Failed))
metrics.RegisterSpanEvent(
Expand All @@ -377,8 +371,6 @@ func (w *Worker) doWork(ctx context.Context, condition *rctypes.Condition, e eve

w.eventAckComplete(e)

publisher.Publish(ctx, task)

metrics.RegisterConditionMetrics(startTS, string(rctypes.Failed))
metrics.RegisterEventCounter(true, "ack")
metrics.RegisterSpanEvent(
Expand All @@ -398,6 +390,9 @@ func (w *Worker) doWork(ctx context.Context, condition *rctypes.Condition, e eve
"status": task.Status,
}).Info("task for device failed")
}

// publish result
publisher.Publish(ctx, task)
}

// runTaskWithMonitor runs the task method based on the parameters, while ack'ing its progress to the NATS JS.
Expand Down

0 comments on commit b42b759

Please sign in to comment.