Merge pull request #309 from sharelatex/fix-compile-check

clean up compile check
This commit is contained in:
Brian Gough 2016-08-31 16:27:37 +01:00 committed by GitHub
commit 1592ca7623
2 changed files with 23 additions and 5 deletions

View file

@ -48,6 +48,10 @@ module.exports = ClsiCookieManager =
multi.exec (err)->
callback(err, serverId)
clearServerId: (project_id, callback = (err)->)->
if !clsiCookiesEnabled
return callback()
rclient.del buildKey(project_id), callback
getCookieJar: (project_id, callback = (err, jar)->)->
if !clsiCookiesEnabled

View file

@ -22,6 +22,7 @@ UserPagesController = require('./Features/User/UserPagesController')
DocumentController = require('./Features/Documents/DocumentController')
CompileManager = require("./Features/Compile/CompileManager")
CompileController = require("./Features/Compile/CompileController")
ClsiCookieManager = require("./Features/Compile/ClsiCookieManager")
HealthCheckController = require("./Features/HealthCheck/HealthCheckController")
ProjectDownloadsController = require "./Features/Downloads/ProjectDownloadsController"
FileStoreController = require("./Features/FileStore/FileStoreController")
@ -251,14 +252,27 @@ module.exports = class Router
apiRouter.get '/health_check/redis', HealthCheckController.checkRedis
apiRouter.get "/status/compiler/:Project_id", AuthorizationMiddlewear.ensureUserCanReadProject, (req, res) ->
project_id = req.params.Project_id
sendRes = _.once (statusCode, message)->
res.writeHead statusCode
res.end message
CompileManager.compile req.params.Project_id, "test-compile", {}, () ->
sendRes 200, "Compiler returned in less than 10 seconds"
setTimeout (() ->
res.status statusCode
res.send message
ClsiCookieManager.clearServerId project_id # force every compile to a new server
# set a timeout
handler = setTimeout (() ->
sendRes 500, "Compiler timed out"
handler = null
), 10000
# use a valid user id for testing
test_user_id = "123456789012345678901234"
# run the compile
CompileManager.compile project_id, test_user_id, {}, (error, status) ->
clearTimeout handler if handler?
if error?
sendRes 500, "Compiler returned error #{error.message}"
else if status is "success"
sendRes 200, "Compiler returned in less than 10 seconds"
else
sendRes 500, "Compiler returned failure #{status}"
apiRouter.get "/ip", (req, res, next) ->
res.send({