Skip to content

Commit

Permalink
fix: Address PR feedback on using go func
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Goodell <[email protected]>
  • Loading branch information
Leonard Goodell committed Jul 27, 2022
1 parent f68bfad commit 30e9bc2
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions internal/core/metadata/application/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ func AddDevice(d models.Device, ctx context.Context, dic *di.Container) (id stri
device := dtos.FromDeviceModelToDTO(d)
go addDeviceCallback(ctx, dic, device)

if err := publishDeviceSystemEvent(common.DeviceSystemEventActionAdd, d, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
go func() {
if err := publishDeviceSystemEvent(common.DeviceSystemEventActionAdd, d, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
}()

return addedDevice.Id, nil
}
Expand All @@ -90,10 +92,12 @@ func DeleteDeviceByName(name string, ctx context.Context, dic *di.Container) err
}
go deleteDeviceCallback(ctx, dic, device)

if err := publishDeviceSystemEvent(common.DeviceSystemEventActionDelete, device, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
go func() {
if err := publishDeviceSystemEvent(common.DeviceSystemEventActionDelete, device, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
}()

return nil
}
Expand Down Expand Up @@ -186,10 +190,12 @@ func PatchDevice(dto dtos.UpdateDevice, ctx context.Context, dic *di.Container)
}
go updateDeviceCallback(ctx, dic, device.ServiceName, device)

if err := publishDeviceSystemEvent(common.DeviceSystemEventActionUpdate, device, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
go func() {
if err := publishDeviceSystemEvent(common.DeviceSystemEventActionUpdate, device, ctx, lc, dic); err != nil {
// Don't fail request if couldn't publish, just log it. Error message already has context.
lc.Error(err.Error())
}
}()

return nil
}
Expand Down

0 comments on commit 30e9bc2

Please sign in to comment.