pulled health check into its own file and use project_id from settings

This commit is contained in:
Henry Oswald 2015-10-16 10:13:54 +01:00
parent 491d4c69b1
commit de9a24f7bb
4 changed files with 49 additions and 41 deletions

View file

@ -25,46 +25,7 @@ app.del '/project/:project_id/doc/:doc_id', HttpController.deleteDoc
app.post '/project/:project_id/archive', HttpController.archiveAllDocs
app.post '/project/:project_id/unarchive', HttpController.unArchiveAllDocs
ObjectId = require("mongojs").ObjectId
request = require("request")
async = require("async")
_ = require("underscore")
crypto = require("crypto")
app.get "/health_check", (req, res)->
doc_id = ObjectId()
project_id = ObjectId()
url = "http://localhost:#{port}/project/#{project_id}/doc/#{doc_id}"
lines = ["smoke test - delete me", "#{crypto.randomBytes(32).toString("hex")}"]
logger.log lines:lines, url:url, doc_id:doc_id, project_id:project_id, "running health check"
jobs = [
(cb)->
opts =
url:url
json: {lines: lines}
request.post(opts, cb)
(cb)->
request.get {url:url, json:true}, (err, res, body)->
if res.statusCode != 200
cb("status code not 200, its #{res.statusCode}")
else if _.isEqual(body.lines, lines) and body._id == doc_id.toString()
cb()
else
cb("lines not equal ")
(cb)->
request.del url, cb
]
async.series jobs, (err)->
if err?
logger.err err:err, "error running health check"
res.send 500
else
res.send()
app.get "/health_check", HttpController.healthCheck
app.get '/status', (req, res)->
res.send('docstore is alive')

View file

@ -0,0 +1,35 @@
ObjectId = require("mongojs").ObjectId
request = require("request")
async = require("async")
_ = require("underscore")
crypto = require("crypto")
settings = require("settings-sharelatex")
port = settings.internal.docstore.port
logger = require "logger-sharelatex"
module.exports =
check : (callback)->
doc_id = ObjectId()
project_id = ObjectId(settings.docstore.healthCheck.project_id)
url = "http://localhost:#{port}/project/#{project_id}/doc/#{doc_id}"
lines = ["smoke test - delete me", "#{crypto.randomBytes(32).toString("hex")}"]
logger.log lines:lines, url:url, doc_id:doc_id, project_id:project_id, "running health check"
jobs = [
(cb)->
opts =
url:url
json: {lines: lines}
request.post(opts, cb)
(cb)->
request.get {url:url, json:true}, (err, res, body)->
if res.statusCode != 200
cb("status code not 200, its #{res.statusCode}")
else if _.isEqual(body.lines, lines) and body._id == doc_id.toString()
cb()
else
cb("health check lines not equal #{body.lines} != #{lines}")
(cb)->
request.del url, cb
]
async.series jobs, callback

View file

@ -1,6 +1,8 @@
DocManager = require "./DocManager"
logger = require "logger-sharelatex"
DocArchive = require "./DocArchiveManager"
HealthChecker = require "./HealthChecker"
module.exports = HttpController =
getDoc: (req, res, next = (error) ->) ->
@ -94,3 +96,11 @@ module.exports = HttpController =
return next(error) if error?
res.send 200
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

@ -10,7 +10,9 @@ module.exports =
mongo:
url: 'mongodb://127.0.0.1/sharelatex'
#docstore:
docstore:
healthCheck:
project_id: "5620bece05509b0a7a3cbc61"
# s3:
# key: ""
# secret: ""