API to pause TCP checks

This commit is contained in:
Praneeth Bodduluri 2015-08-26 19:10:22 +05:30 committed by Pablo Carranza Vélez
parent 177e9ddd7c
commit 03299d77f5
4 changed files with 33 additions and 5 deletions

View File

@ -17,7 +17,7 @@
"knex": "~0.8.3",
"lodash": "^3.0.0",
"mixpanel": "0.0.20",
"network-checker": "~0.0.4",
"network-checker": "~0.0.5",
"ngrok": "~0.1.97",
"pinejs-client": "^1.4.0",
"pubnub": "^3.7.13",

View File

@ -9,7 +9,7 @@ bodyParser = require 'body-parser'
request = require 'request'
config = require './config'
module.exports = (secret) ->
module.exports = (secret,disableCheck) ->
api = express()
api.use(bodyParser())
api.use (req, res, next) ->
@ -84,4 +84,12 @@ module.exports = (secret) ->
.catch (err) ->
res.status(503).send(err?.message or err or 'Unknown error')
api.post '/tcp-ping', (req, res) ->
disableCheck(false)
res.status(200).send('OK\n')
api.delete '/tcp-ping', (req, res) ->
disableCheck(true)
res.status(200).send('OK\n')
return api

View File

@ -37,7 +37,7 @@ knex.init.then ->
console.log('Starting API server..')
secret = config.forceApiSecret ? randomstring.generate()
api(secret).listen(config.listenPort)
api(secret,utils.disableCheck).listen(config.listenPort)
# Let API know what version we are, and our api connection info.
console.log('Updating supervisor version and api info')
@ -49,7 +49,7 @@ knex.init.then ->
provisioning_state: ''
download_progress: null
)
console.log('Starting Apps..')
knex('app').select()
.then (apps) ->

View File

@ -66,9 +66,29 @@ networkPattern =
exports.blink = blink
exports.pauseCheck = pauseCheck = false
# options: An object of net.connect options, with the addition of:
# timeout: 10s
checkHost = (options) ->
new Promise (resolve, reject) ->
if exports.pauseCheck
resolve()
else
reject()
.then ->
return true
.catch ->
return networkCheck.checkHost(options)
customMonitor = (options, fn) ->
networkCheck.monitor(checkHost, options, fn)
exports.disableCheck = (disable) ->
exports.pauseCheck=disable
exports.connectivityCheck = _.once ->
parsedUrl = url.parse(config.apiEndpoint)
networkCheck.monitorHost
customMonitor
host: parsedUrl.hostname
port: parsedUrl.port ? (if parsedUrl.protocol is 'https:' then 443 else 80)
interval: 10 * 1000