check _checkRecoursesForErrors before compile

This commit is contained in:
Henry Oswald 2016-06-01 16:46:41 +01:00
parent 66ad587c9c
commit 8a5cb86c31
2 changed files with 54 additions and 26 deletions

View file

@ -17,17 +17,24 @@ module.exports = ClsiManager =
ClsiManager._buildRequest project_id, options, (error, req) ->
return callback(error) if error?
logger.log project_id: project_id, "sending compile to CLSI"
ClsiManager._postToClsi project_id, req, options.compileGroup, (error, response) ->
if error?
logger.err err:error, project_id:project_id, "error sending request to clsi"
return callback(error)
logger.log project_id: project_id, outputFilesLength: response?.outputFiles?.length, status: response?.status, "received compile response from CLSI"
ClsiCookieManager._getServerId project_id, (err, clsiServerId)->
if err?
logger.err err:err, project_id:project_id, "error getting server id"
return callback(err)
outputFiles = ClsiManager._parseOutputFiles(project_id, response?.compile?.outputFiles)
callback(null, response?.compile?.status, outputFiles, clsiServerId)
ClsiManager._checkRecoursesForErrors req.compile.resources, (err, problems)->
if err?
logger.err err, project_id, "could not check resources for potential problems before sending to clsi"
return callback(err)
if problems?
logger.log project_id:project_id, problems:problems, "problems with users latex before compile was attempted"
return callback(null, problems)
ClsiManager._postToClsi project_id, req, options.compileGroup, (error, response) ->
if error?
logger.err err:error, project_id:project_id, "error sending request to clsi"
return callback(error)
logger.log project_id: project_id, outputFilesLength: response?.outputFiles?.length, status: response?.status, "received compile response from CLSI"
ClsiCookieManager._getServerId project_id, (err, clsiServerId)->
if err?
logger.err err:err, project_id:project_id, "error getting server id"
return callback(err)
outputFiles = ClsiManager._parseOutputFiles(project_id, response?.compile?.outputFiles)
callback(null, response?.compile?.status, outputFiles, clsiServerId)
deleteAuxFiles: (project_id, options, callback = (error) ->) ->
compilerUrl = @_getCompilerUrl(options?.compileGroup)
@ -158,17 +165,25 @@ module.exports = ClsiManager =
_checkRecoursesForErrors: (resources, callback)->
jobs =
duplicatePaths: (cb)->
ClsiManager._checkForFilesWithSameName resources, cb
ClsiManager._checkForDuplicatePaths resources, cb
conflictedPaths: (cb)->
ClsiManager._checkForConflictingPaths resources, cb
sizeCheck: (cb)->
ClsiManager._checkDocsAreUnderSizeLimit resources, cb
async.series jobs, callback
_checkForFilesWithSameName: (resources, callback)->
async.series jobs, (err, problems)->
if err?
return callback(err)
problems = _.omit(problems, _.isEmpty)
if _.isEmpty(problems)
return callback()
else
callback(null, problems)
_checkForDuplicatePaths: (resources, callback)->
paths = _.pluck(resources, 'path')
duplicates = _.filter paths, (path)->
@ -211,10 +226,11 @@ module.exports = ClsiManager =
return result
tooLarge = totalSize > FIVEMB
sizedResources = _.sortBy(sizedResources, "size").slice(10).reverse()
callback(null, {resources:sizedResources, totalSize:totalSize, tooLarge:tooLarge})
if !tooLarge
return callback()
else
sizedResources = _.sortBy(sizedResources, "size").slice(10).reverse()
return callback(null, {resources:sizedResources, totalSize:totalSize})

View file

@ -335,18 +335,31 @@ describe "ClsiManager", ->
modified: ["more stuff"]
}]
it "should call _checkForFilesWithSameName and _checkForConflictingPaths", (done)->
it "should call _checkForDuplicatePaths and _checkForConflictingPaths", (done)->
@ClsiManager._checkForFilesWithSameName = sinon.stub().callsArgWith(1)
@ClsiManager._checkForDuplicatePaths = sinon.stub().callsArgWith(1)
@ClsiManager._checkForConflictingPaths = sinon.stub().callsArgWith(1)
@ClsiManager._checkDocsAreUnderSizeLimit = sinon.stub().callsArgWith(1)
@ClsiManager._checkRecoursesForErrors @resources, =>
@ClsiManager._checkForFilesWithSameName.called.should.equal true
@ClsiManager._checkRecoursesForErrors @resources, (err, problems)=>
@ClsiManager._checkForDuplicatePaths.called.should.equal true
@ClsiManager._checkForConflictingPaths.called.should.equal true
@ClsiManager._checkDocsAreUnderSizeLimit.called.should.equal true
expect(problems).to.not.exist
done()
describe "_checkForFilesWithSameName", ->
it "should remove undefined errors", (done)->
@ClsiManager._checkForDuplicatePaths = sinon.stub().callsArgWith(1, null, [path:"something/here"])
@ClsiManager._checkForConflictingPaths = sinon.stub().callsArgWith(1, null, [])
@ClsiManager._checkDocsAreUnderSizeLimit = sinon.stub().callsArgWith(1, null)
@ClsiManager._checkRecoursesForErrors @resources, (err, problems)=>
problems.duplicatePaths[0].path.should.equal "something/here"
expect(problems.conflictedPaths).to.not.exist
expect(problems.sizeCheck).to.not.exist
done()
describe "_checkForDuplicatePaths", ->
it "should flag up 2 nested files with same path", (done)->
@ -355,7 +368,7 @@ describe "ClsiManager", ->
url: "http://somwhere.com"
})
@ClsiManager._checkForFilesWithSameName @resources, (err, duplicateErrors)->
@ClsiManager._checkForDuplicatePaths @resources, (err, duplicateErrors)->
duplicateErrors.length.should.equal 1
duplicateErrors[0].path.should.equal "chapters/chapter1"
done()
@ -397,7 +410,6 @@ describe "ClsiManager", ->
@resources.push({path:"chapters/chapter1.tex",url: "http://somwhere.com"})
@ClsiManager._checkDocsAreUnderSizeLimit @resources, (err, sizeError)->
sizeError.tooLarge.should.equal true
sizeError.totalSize.should.equal 10000016
sizeError.resources.length.should.equal 10
sizeError.resources[0].path.should.equal "massive.tex"