Skip to content

FS-963 Fix duplicate message publish on success and fix lint issue G601 #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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