mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-23 23:42:29 +00:00
Move the connectivity check into utils.
This commit is contained in:
parent
63f1d66402
commit
2557ebcfc2
@ -9,32 +9,9 @@ config = require './config'
|
||||
|
||||
utils.mixpanelTrack('Supervisor start')
|
||||
|
||||
connectivityState = true # Used to prevent multiple messages when disconnected
|
||||
|
||||
ensureConnected = (continuous = false) ->
|
||||
utils.checkConnectivity()
|
||||
.then (connected) ->
|
||||
if not connected
|
||||
if connectivityState
|
||||
console.log('Waiting for connectivity...')
|
||||
connectivityState = false
|
||||
interval = setInterval(utils.blink,400)
|
||||
Promise.delay(2000)
|
||||
.then ->
|
||||
# Clear the blinks after 2 second
|
||||
clearInterval(interval)
|
||||
ensureConnected(continuous)
|
||||
else
|
||||
if not connectivityState
|
||||
console.log('Internet Connectivity: OK')
|
||||
connectivityState = true
|
||||
if continuous
|
||||
setTimeout(->
|
||||
ensureConnected(continuous)
|
||||
, 10 * 1000) # Every 10 seconds perform this check.
|
||||
|
||||
console.log('Starting connectivity check..')
|
||||
ensureConnected(true)
|
||||
utils.connectivityCheck(true)
|
||||
|
||||
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
|
||||
if not uuid?.value
|
||||
|
@ -5,6 +5,8 @@ config = require './config'
|
||||
mixpanel = require 'mixpanel'
|
||||
request = require './request'
|
||||
|
||||
utils = exports
|
||||
|
||||
# Parses package.json and returns resin-supervisor's version
|
||||
exports.supervisorVersion = require('../package.json').version
|
||||
|
||||
@ -72,3 +74,27 @@ exports.checkConnectivity = ->
|
||||
return response.statusCode in [ 200, 304 ]
|
||||
.catch ->
|
||||
return false
|
||||
|
||||
exports.connectivityCheck = do ->
|
||||
connectivityState = true # Used to prevent multiple messages when disconnected
|
||||
(continuous = false) ->
|
||||
utils.checkConnectivity()
|
||||
.then (connected) ->
|
||||
if not connected
|
||||
if connectivityState
|
||||
console.log('Waiting for connectivity...')
|
||||
connectivityState = false
|
||||
interval = setInterval(utils.blink,400)
|
||||
Promise.delay(2000)
|
||||
.then ->
|
||||
# Clear the blinks after 2 second
|
||||
clearInterval(interval)
|
||||
utils.connectivityCheck(continuous)
|
||||
else
|
||||
if not connectivityState
|
||||
console.log('Internet Connectivity: OK')
|
||||
connectivityState = true
|
||||
if continuous
|
||||
setTimeout(->
|
||||
utils.connectivityCheck(continuous)
|
||||
, 10 * 1000) # Every 10 seconds perform this check.
|
Loading…
Reference in New Issue
Block a user