mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
added healthcheck
This commit is contained in:
parent
ad144371d0
commit
c44d5b1b3d
4 changed files with 44 additions and 2 deletions
|
@ -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
|
||||
|
|
31
services/track-changes/app/coffee/HealthChecker.coffee
Normal file
31
services/track-changes/app/coffee/HealthChecker.coffee
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue