Auto-merge for PR #596 via VersionBot

Back off fetching the target state exponentially, for faster retries …
This commit is contained in:
resin-io-versionbot[bot] 2018-03-29 09:49:59 +00:00 committed by GitHub
commit eeec258d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 17 deletions

View File

@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
This project adheres to [Semantic Versioning](http://semver.org/).
## v7.1.22 - 2018-03-29
* Back off fetching the target state exponentially, for faster retries when there's no connectivity #596 [Pablo Carranza Velez]
## v7.1.21 - 2018-03-27
* Handle incorrectly parsed env vars from docker inspect #605 [Cameron Diver]

View File

@ -1,7 +1,7 @@
{
"name": "resin-supervisor",
"description": "This is resin.io's Supervisor, a program that runs on IoT devices and has the task of running user Apps (which are Docker containers), and updating them as Resin's API informs it to.",
"version": "7.1.21",
"version": "7.1.22",
"license": "Apache-2.0",
"repository": {
"type": "git",

View File

@ -8,7 +8,7 @@ express = require 'express'
bodyParser = require 'body-parser'
Lock = require 'rwlock'
{ request, requestOpts } = require './lib/request'
{ checkTruthy } = require './lib/validation'
{ checkTruthy, checkInt } = require './lib/validation'
DuplicateUuidError = (err) ->
_.startsWith(err.message, '"uuid" must be unique')
@ -26,6 +26,7 @@ createAPIBinderRouter = (apiBinder) ->
apiBinder.eventTracker.track('Update notification')
if apiBinder.readyForUpdates
apiBinder.getAndSetTargetState(req.body.force)
.catchReturn()
res.sendStatus(204)
return router
@ -40,6 +41,7 @@ module.exports = class APIBinder
@_targetStateInterval = null
@reportPending = false
@stateReportErrors = 0
@targetStateFetchErrors = 0
@router = createAPIBinderRouter(this)
_lock = new Lock()
@_writeLock = Promise.promisify(_lock.async.writeLock)
@ -332,27 +334,31 @@ module.exports = class APIBinder
.then =>
@lastTarget = _.cloneDeep(targetState)
@deviceState.triggerApplyTarget({ force })
.catch (err) ->
.tapCatch (err) ->
console.error("Failed to get target state for device: #{err}")
.finally =>
@lastTargetStateFetch = process.hrtime()
_pollTargetState: =>
@config.get('appUpdatePollInterval')
.then (appUpdatePollInterval) =>
if @_targetStateInterval?
clearInterval(@_targetStateInterval)
@_targetStateInterval = setInterval(@getAndSetTargetState, appUpdatePollInterval)
@getAndSetTargetState()
return null
@getAndSetTargetState()
.then =>
@targetStateFetchErrors = 0
@config.get('appUpdatePollInterval')
.catch =>
@targetStateFetchErrors += 1
@config.get('appUpdatePollInterval')
.then (appUpdatePollInterval) =>
Math.min(appUpdatePollInterval, 15000 * 2 ** (@targetStateFetchErrors - 1))
.then(checkInt)
.then(Promise.delay)
.then(@_pollTargetState)
startTargetStatePoll: ->
if !@resinApi?
throw new Error('Trying to start poll without initializing API client')
@_pollTargetState()
@config.on 'change', (changedConfig) =>
if changedConfig.appUpdatePollInterval?
@_pollTargetState()
startTargetStatePoll: =>
Promise.try =>
if !@resinApi?
throw new Error('Trying to start poll without initializing API client')
@_pollTargetState()
return null
_getStateDiff: =>
diff = {