2015-10-19 05:59:39 -04:00
|
|
|
ObjectId = require("mongojs").ObjectId
|
|
|
|
request = require("request")
|
|
|
|
async = require("async")
|
|
|
|
settings = require("settings-sharelatex")
|
|
|
|
port = settings.internal.trackchanges.port
|
|
|
|
logger = require "logger-sharelatex"
|
2016-01-27 11:04:55 -05:00
|
|
|
LockManager = require "./LockManager"
|
2015-10-19 05:59:39 -04:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
check : (callback)->
|
|
|
|
project_id = ObjectId(settings.trackchanges.healthCheck.project_id)
|
|
|
|
url = "http://localhost:#{port}/project/#{project_id}"
|
|
|
|
logger.log project_id:project_id, "running health check"
|
|
|
|
jobs = [
|
2015-10-29 06:52:23 -04:00
|
|
|
(cb)->
|
|
|
|
request.get {url:"http://localhost:#{port}/check_lock", timeout:3000}, (err, res, body) ->
|
|
|
|
if err?
|
2016-03-03 05:50:55 -05:00
|
|
|
logger.err err:err, project_id:project_id, "error checking lock for health check"
|
2015-10-29 06:52:23 -04:00
|
|
|
cb(err)
|
|
|
|
else if res?.statusCode != 200
|
|
|
|
cb("status code not 200, it's #{res.statusCode}")
|
|
|
|
else
|
|
|
|
cb()
|
2015-10-19 05:59:39 -04:00
|
|
|
(cb)->
|
2017-04-12 11:47:34 -04:00
|
|
|
request.post {url:"#{url}/flush", timeout:10000}, (err, res, body) ->
|
2015-10-19 05:59:39 -04:00
|
|
|
if err?
|
2016-03-03 05:50:55 -05:00
|
|
|
logger.err err:err, project_id:project_id, "error flushing for health check"
|
2015-10-19 05:59:39 -04:00
|
|
|
cb(err)
|
|
|
|
else if res?.statusCode != 204
|
|
|
|
cb("status code not 204, it's #{res.statusCode}")
|
|
|
|
else
|
|
|
|
cb()
|
|
|
|
(cb)->
|
2017-04-12 11:47:34 -04:00
|
|
|
request.get {url:"#{url}/updates", timeout:10000}, (err, res, body)->
|
2015-10-19 05:59:39 -04:00
|
|
|
if err?
|
2016-03-03 05:50:55 -05:00
|
|
|
logger.err err:err, project_id:project_id, "error getting updates for health check"
|
2015-10-19 05:59:39 -04:00
|
|
|
cb(err)
|
|
|
|
else if res?.statusCode != 200
|
|
|
|
cb("status code not 200, it's #{res.statusCode}")
|
|
|
|
else
|
|
|
|
cb()
|
|
|
|
]
|
|
|
|
async.series jobs, callback
|
2016-01-27 11:04:55 -05:00
|
|
|
|
|
|
|
checkLock: (callback) ->
|
|
|
|
LockManager.healthCheck callback
|