Merge pull request #316 from resin-io/fix-acknowledged-state

Do not use parsed JSON to compare dep. device state
This commit is contained in:
Pablo Carranza Vélez 2016-10-11 13:03:47 -03:00 committed by GitHub
commit c1788ec045
2 changed files with 11 additions and 6 deletions

View File

@ -1,3 +1,5 @@
Do not use parsed JSON to compare dep. device state [Pablo]
# v2.6.0 # v2.6.0
* Fix docker utils getImageEnv by correctly parsing the returned array [Pablo] * Fix docker utils getImageEnv by correctly parsing the returned array [Pablo]

View File

@ -312,6 +312,13 @@ getHookEndpoint = (appId) ->
conf.RESIN_DEPENDENT_DEVICES_HOOK_ADDRESS ? conf.RESIN_DEPENDENT_DEVICES_HOOK_ADDRESS ?
"#{appConfig.proxyvisorHookReceiver}/v1/devices/" "#{appConfig.proxyvisorHookReceiver}/v1/devices/"
formatTargetAsState = (device) ->
return {
commit: device.targetCommit
environment: device.targetEnvironment
config: device.targetConfig
}
do -> do ->
acknowledgedState = {} acknowledgedState = {}
sendUpdate = (device, endpoint) -> sendUpdate = (device, endpoint) ->
@ -327,7 +334,7 @@ do ->
} }
.spread (response, body) -> .spread (response, body) ->
if response.statusCode == 200 if response.statusCode == 200
acknowledgedState[device.uuid] = _.omit(stateToSend, 'appId') acknowledgedState[device.uuid] = formatTargetAsState(device)
else else
acknowledgedState[device.uuid] = null acknowledgedState[device.uuid] = null
throw new Error("Hook returned #{response.statusCode}: #{body}") if response.statusCode != 202 throw new Error("Hook returned #{response.statusCode}: #{body}") if response.statusCode != 202
@ -350,11 +357,7 @@ do ->
knex('dependentDevice').select() knex('dependentDevice').select()
.map (device) -> .map (device) ->
currentState = _.pick(device, 'commit', 'environment', 'config') currentState = _.pick(device, 'commit', 'environment', 'config')
targetState = { targetState = formatTargetAsState(device)
commit: device.targetCommit
environment: device.targetEnvironment
config: device.targetConfig
}
endpoints[device.appId] ?= getHookEndpoint(device.appId) endpoints[device.appId] ?= getHookEndpoint(device.appId)
endpoints[device.appId] endpoints[device.appId]
.then (endpoint) -> .then (endpoint) ->