From f43afd4a95f9450a48ca195d77bd8224ed983230 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Wed, 1 Oct 2014 17:00:21 +0100 Subject: [PATCH] Retry the bootstrap process if it fails - this means that we remove a point of failure (the previous connectivity check barrier merely reduced the chance of hitting that failure point) --- src/app.coffee | 8 ++++++-- src/config.coffee | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app.coffee b/src/app.coffee index 7cb844ef..b3f2f7d2 100644 --- a/src/app.coffee +++ b/src/app.coffee @@ -37,9 +37,13 @@ ensureConnected = (continuous = false) -> knex('config').select('value').where(key: 'uuid').then ([ uuid ]) -> if not uuid?.value console.log('New device detected. Bootstrapping..') - ensureConnected().then -> + retryingBootstrap = -> utils.mixpanelTrack('Device bootstrap') - bootstrap() + bootstrap().catch (err) -> + utils.mixpanelTrack("Device bootstrap failed due to #{err?.message}, retrying in #{config.bootstrapRetryDelay}ms") + Promise.delay(config.bootstrapRetryDelay) + .then(retryingBootstrap) + retryingBootstrap() else uuid.value .then (uuid) -> diff --git a/src/config.coffee b/src/config.coffee index 0440ffcb..faceb1f4 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -9,6 +9,7 @@ module.exports = config = localImage: process.env.SUPERVISOR_IMAGE ? 'resin/rpi-supervisor' configMountPoint: process.env.CONFIG_MOUNT_POINT ? '/mnt/mmcblk0p1/config.json' ledFile: process.env.LED_FILE ? '/sys/class/leds/led0/brightness' + bootstrapRetryDelay: process.env.BOOTSTRAP_RETRY_DELAY_MS ? 30000 successMessage: 'SUPERVISOR OK' config.heartbeatEndpoint = config.apiEndpoint + '/ping'