added healthcheck

This commit is contained in:
Brian Gough 2015-10-19 10:59:39 +01:00
parent ad144371d0
commit c44d5b1b3d
4 changed files with 44 additions and 2 deletions

View file

@ -47,6 +47,8 @@ app.post "/pack", (req, res, next) ->
app.get "/status", (req, res, next) ->
res.send "track-changes is alive"
app.get "/health_check", HttpController.healthCheck
app.use (error, req, res, next) ->
logger.error err: error, "an internal error occured"
res.send 500

View file

@ -0,0 +1,31 @@
ObjectId = require("mongojs").ObjectId
request = require("request")
async = require("async")
settings = require("settings-sharelatex")
port = settings.internal.trackchanges.port
logger = require "logger-sharelatex"
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 = [
(cb)->
request.post {url:"#{url}/flush", timeout:3000}, (err, res, body) ->
if err?
cb(err)
else if res?.statusCode != 204
cb("status code not 204, it's #{res.statusCode}")
else
cb()
(cb)->
request.get {url:"#{url}/updates", timeout:3000}, (err, res, body)->
if err?
cb(err)
else if res?.statusCode != 200
cb("status code not 200, it's #{res.statusCode}")
else
cb()
]
async.series jobs, callback

View file

@ -4,6 +4,7 @@ PackManager = require "./PackManager"
RestoreManager = require "./RestoreManager"
logger = require "logger-sharelatex"
DocArchiveManager = require "./DocArchiveManager"
HealthChecker = require "./HealthChecker"
module.exports = HttpController =
flushDoc: (req, res, next = (error) ->) ->
@ -81,3 +82,11 @@ module.exports = HttpController =
DocArchiveManager.unArchiveAllDocsChanges project_id, (error) ->
return next(error) if error?
res.send 204
healthCheck: (req, res)->
HealthChecker.check (err)->
if err?
logger.err err:err, "error performing health check"
res.send 500
else
res.send 200

View file

@ -16,7 +16,7 @@
"logger-sharelatex": "git+https://github.com/sharelatex/logger-sharelatex.git#v1.0.0",
"metrics-sharelatex": "git+https://github.com/sharelatex/metrics-sharelatex.git#v1.0.0",
"request": "~2.33.0",
"redis-sharelatex": "~0.0.4",
"redis-sharelatex": "~0.0.9",
"redis": "~0.10.1",
"underscore": "~1.7.0",
"mongo-uri": "^0.1.2",