Reconfigure internal CLSI call to understand more than just success/failure

This commit is contained in:
James Allen 2014-05-19 13:46:22 +01:00
parent a53d767eca
commit 6c5a2c2740
5 changed files with 46 additions and 12 deletions

View file

@ -17,7 +17,7 @@ module.exports = ClsiManager =
logger.log project_id: project_id, response: response, "received compile response from CLSI"
callback(
null
(response?.compile?.status == "success")
response?.compile?.status
ClsiManager._parseOutputFiles(project_id, response?.compile?.outputFiles)
)
@ -32,6 +32,12 @@ module.exports = ClsiManager =
json: req
jar: false
}, (error, response, body) ->
return callback(error) if error?
if 200 <= response.statusCode < 300
callback null, body
else
error = new Error("CLSI returned non-success code: #{response.statusCode}")
logger.error err: error, project_id: project_id, "CLSI returned failure code"
callback error, body
_parseOutputFiles: (project_id, rawOutputFiles = []) ->

View file

@ -31,10 +31,10 @@ module.exports = CompileManager =
return callback(error) if error?
DocumentUpdaterHandler.flushProjectToMongo project_id, (error) ->
return callback(error) if error?
ClsiManager.sendRequest project_id, (error, success, outputFiles) ->
ClsiManager.sendRequest project_id, (error, status, outputFiles) ->
return callback(error) if error?
logger.log files: outputFiles, "output files"
callback(null, success, outputFiles)
callback(null, status, outputFiles)
getLogLines: (project_id, callback)->
Metrics.inc "editor.raw-logs"

View file

@ -322,7 +322,8 @@ module.exports = class Router
client.on 'pdfProject', (opts, callback)->
AuthorizationManager.ensureClientCanViewProject client, (error, project_id) =>
CompileManager.compile(project_id, user._id, opts, callback)
CompileManager.compile project_id, user._id, opts, (error, status, outputFiles) ->
return callback error, status == "success", outputFiles
client.on 'enableversioningController', (callback)->
AuthorizationManager.ensureClientCanEditProject client, (error, project_id) =>

View file

@ -17,7 +17,8 @@ describe "ClsiManager", ->
url: "http://clsi.example.com"
"../../models/Project": Project: @Project = {}
"../Project/ProjectEntityHandler": @ProjectEntityHandler = {}
"logger-sharelatex": @logger = { log: sinon.stub() }
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"request": @request = {}
@project_id = "project-id"
@callback = sinon.stub()
@ -29,7 +30,7 @@ describe "ClsiManager", ->
beforeEach ->
@ClsiManager._postToClsi = sinon.stub().callsArgWith(2, null, {
compile:
status: "success"
status: @status = "success"
outputFiles: [{
url: "#{@settings.apis.clsi.url}/project/#{@project_id}/output/output.pdf"
type: "pdf"
@ -58,18 +59,18 @@ describe "ClsiManager", ->
path: "output.log"
type: "log"
}]
@callback.calledWith(null, true, outputFiles).should.equal true
@callback.calledWith(null, @status, outputFiles).should.equal true
describe "with a failed compile", ->
beforeEach ->
@ClsiManager._postToClsi = sinon.stub().callsArgWith(2, null, {
compile:
status: "failure"
status: @status = "failure"
})
@ClsiManager.sendRequest @project_id, @callback
it "should call the callback with a failure statue", ->
@callback.calledWith(null, false).should.equal true
@callback.calledWith(null, @status).should.equal true
describe "_buildRequest", ->
beforeEach ->
@ -165,3 +166,31 @@ describe "ClsiManager", ->
expect(@error).to.exist
describe '_postToClsi', ->
beforeEach ->
@req = { mock: "req" }
describe "successfully", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 204}, @body = { mock: "foo" })
@ClsiManager._postToClsi @project_id, @req, @callback
it 'should send the request to the CLSI', ->
url = "#{@settings.apis.clsi.url}/project/#{@project_id}/compile"
@request.post.calledWith({
url: url
json: @req
jar: false
}).should.equal true
it "should call the callback with the body and no error", ->
@callback.calledWith(null, @body).should.equal true
describe "when the CLSI returns an error", ->
beforeEach ->
@request.post = sinon.stub().callsArgWith(1, null, {statusCode: 500}, @body = { mock: "foo" })
@ClsiManager._postToClsi @project_id, @req, @callback
it "should call the callback with the body and the error", ->
@callback.calledWith(new Error("CLSI returned non-success code: 500"), @body).should.equal true

View file

@ -21,7 +21,6 @@ describe "CompileManager", ->
"../Project/ProjectRootDocManager": @ProjectRootDocManager = {}
"../../models/Project": Project: @Project = {}
"./ClsiManager": @ClsiManager = {}
"../../managers/LatexManager": @LatexManager = {}
"../../infrastructure/RateLimiter": @ratelimiter
"../../infrastructure/Metrics": @Metrics =
Timer: class Timer
@ -38,7 +37,6 @@ describe "CompileManager", ->
@CompileManager._ensureRootDocumentIsSet = sinon.stub().callsArgWith(1, null)
@DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().callsArgWith(1, null)
@ClsiManager.sendRequest = sinon.stub().callsArgWith(1, null, @status = "mock-status")
@LatexManager.compile = sinon.stub().callsArgWith(1, null, @status = "mock-status")
describe "succesfully", ->
beforeEach ->