Merge pull request #781 from balena-io/fix-api-update-forced

fix: When calling the /v1/update endpoint, always trigger a target st…
This commit is contained in:
Pablo Carranza Vélez 2018-10-31 15:42:13 -07:00 committed by GitHub
commit 7834a5bf82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,7 +31,7 @@ createAPIBinderRouter = (apiBinder) ->
router.post '/v1/update', (req, res) ->
apiBinder.eventTracker.track('Update notification')
if apiBinder.readyForUpdates
apiBinder.getAndSetTargetState(req.body.force)
apiBinder.getAndSetTargetState(req.body.force, true)
.catchReturn()
res.sendStatus(204)
return router
@ -363,11 +363,11 @@ module.exports = class APIBinder
.timeout(apiTimeout)
# Get target state from API, set it on @deviceState and trigger a state application
getAndSetTargetState: (force) =>
getAndSetTargetState: (force, isFromAPI = false) =>
Promise.using @_lockGetTarget(), =>
@getTargetState()
.then (targetState) =>
if !_.isEqual(targetState, @lastTarget)
if isFromAPI or !_.isEqual(targetState, @lastTarget)
@deviceState.setTarget(targetState)
.then =>
@lastTarget = _.cloneDeep(targetState)