Skip to content
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

fix(metadata): Notify both device services when a Device is moved… #2717

Merged
merged 1 commit into from
Sep 29, 2020
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
11 changes: 6 additions & 5 deletions internal/core/metadata/operators/device/events.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package device

type DeviceEvent struct {
DeviceId string
DeviceName string
Error error
HttpMethod string
ServiceId string
DeviceId string
DeviceName string
Error error
HttpMethod string
ServiceId string
SecondaryServiceId string
}
13 changes: 13 additions & 0 deletions internal/core/metadata/operators/device/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ func (op deviceNotifier) Execute() {
if err := op.callback(service, deviceId, httpMethod, models.DEVICE); err != nil {
op.logger.Error(err.Error())
}

if msg.SecondaryServiceId != "" {
// Callback for secondary device service
service, err := op.database.GetDeviceServiceById(msg.SecondaryServiceId)
if err != nil {
op.logger.Error(err.Error())
return
}

if err := op.callback(service, deviceId, httpMethod, models.DEVICE); err != nil {
op.logger.Error(err.Error())
}
}
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/core/metadata/operators/device/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func (op updateDevice) Execute() (err error) {
evt.HttpMethod = http.MethodPut
evt.ServiceId = op.device.Service.Id

if op.device.Service.Id != oldDevice.Service.Id {
evt.SecondaryServiceId = oldDevice.Service.Id
}

op.events <- evt

return nil
Expand Down