Turn the connectivity check into a singleton, so we only have one running.

This commit is contained in:
Pagan Gazzard 2014-12-10 19:44:32 +00:00 committed by Pablo Carranza Vélez
parent 2557ebcfc2
commit 5e380fb66a
2 changed files with 5 additions and 7 deletions

View File

@ -11,7 +11,7 @@ utils.mixpanelTrack('Supervisor start')
console.log('Starting connectivity check..')
utils.connectivityCheck(true)
utils.connectivityCheck()
knex('config').select('value').where(key: 'uuid').then ([ uuid ]) ->
if not uuid?.value

View File

@ -77,7 +77,7 @@ exports.checkConnectivity = ->
exports.connectivityCheck = do ->
connectivityState = true # Used to prevent multiple messages when disconnected
(continuous = false) ->
_check = ->
utils.checkConnectivity()
.then (connected) ->
if not connected
@ -89,12 +89,10 @@ exports.connectivityCheck = do ->
.then ->
# Clear the blinks after 2 second
clearInterval(interval)
utils.connectivityCheck(continuous)
_check()
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.
setTimeout(_check, 10 * 1000) # Every 10 seconds perform this check.
return _.once(_check)