Skip to content

Commit

Permalink
Merge pull request #2717 from iain-anderson/device-moved
Browse files Browse the repository at this point in the history
fix(metadata): Notify both device services when a Device is moved…
  • Loading branch information
cloudxxx8 authored Sep 29, 2020
2 parents 486acce + bea4f5e commit 1366034
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
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

0 comments on commit 1366034

Please sign in to comment.