Automatically clear CLSI cache when compile fails

This commit is contained in:
James Allen 2014-05-19 16:10:41 +01:00
parent 7fed2155be
commit a45200dfe3
6 changed files with 55 additions and 4 deletions

View file

@ -26,6 +26,9 @@ module.exports = ClsiManager =
return callback(error) if error?
callback null, body?.split("\n") or []
deleteAuxFiles: (project_id, callback = (error) ->) ->
request.del "#{Settings.apis.clsi.url}/project/#{project_id}", callback
_postToClsi: (project_id, req, callback = (error, response) ->) ->
request.post {
url: "#{Settings.apis.clsi.url}/project/#{project_id}/compile"

View file

@ -1,6 +1,7 @@
Metrics = require "../../infrastructure/Metrics"
Project = require("../../models/Project").Project
CompileManager = require("./CompileManager")
ClsiManager = require("./ClsiManager")
logger = require "logger-sharelatex"
request = require "request"
Settings = require "settings-sharelatex"
@ -35,7 +36,9 @@ module.exports = CompileController =
deleteAuxFiles: (req, res, next) ->
project_id = req.params.Project_id
CompileController.proxyToClsi("/project/#{project_id}", req, res, next)
ClsiManager.deleteAuxFiles project_id, (error) ->
return next(error) if error?
res.send(200)
compileAndDownloadPdf: (req, res, next)->
project_id = req.params.project_id

View file

@ -33,8 +33,16 @@ module.exports = CompileManager =
ClsiManager.sendRequest project_id, (error, status, outputFiles) ->
return callback(error) if error?
logger.log files: outputFiles, "output files"
if status == "failure"
# Sometimes compiles fail because the project gets in a broken
# state in LaTeX. So always clear cache on a failure.
# Can do this in the background.
ClsiManager.deleteAuxFiles project_id
callback(null, status, outputFiles)
getLogLines: (project_id, callback)->
Metrics.inc "editor.raw-logs"
ClsiManager.getLogLines project_id, (error, logLines)->

View file

@ -72,6 +72,19 @@ describe "ClsiManager", ->
it "should call the callback with a failure statue", ->
@callback.calledWith(null, @status).should.equal true
describe "deleteAuxFiles", ->
beforeEach ->
@request.del = sinon.stub().callsArg(1)
@ClsiManager.deleteAuxFiles @project_id, @callback
it "should call the delete method in the CLSI", ->
@request.del
.calledWith("#{@settings.apis.clsi.url}/project/#{@project_id}")
.should.equal true
it "should call the callback", ->
@callback.called.should.equal true
describe "_buildRequest", ->
beforeEach ->
@project =

View file

@ -21,6 +21,7 @@ describe "CompileController", ->
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
"../../infrastructure/Metrics": @Metrics = { inc: sinon.stub() }
"./CompileManager":@CompileManager
"./ClsiManager": @ClsiManager
"../Authentication/AuthenticationController": @AuthenticationController = {}
@project_id = "project-id"
@next = sinon.stub()
@ -144,14 +145,20 @@ describe "CompileController", ->
describe "deleteAuxFiles", ->
beforeEach ->
@CompileController.proxyToClsi = sinon.stub()
@ClsiManager.deleteAuxFiles = sinon.stub().callsArg(1)
@req.params =
Project_id: @project_id
@res.send = sinon.stub()
@CompileController.deleteAuxFiles @req, @res, @next
it "should proxy to the CLSI", ->
@CompileController.proxyToClsi
.calledWith("/project/#{@project_id}", @req, @res, @next)
@ClsiManager.deleteAuxFiles
.calledWith(@project_id)
.should.equal true
it "should return a 200", ->
@res.send
.calledWith(200)
.should.equal true
describe "compileAndDownloadPdf", ->

View file

@ -75,6 +75,23 @@ describe "CompileManager", ->
@logger.log
.calledWith(project_id: @project_id, user_id: @user_id, "compiling project")
.should.equal true
describe "when the compile fails", ->
beforeEach ->
@CompileManager._checkIfAutoCompileLimitHasBeenHit = (_, cb)-> cb(null, true)
@ClsiManager.deleteAuxFiles = sinon.stub()
@ClsiManager.sendRequest = sinon.stub().callsArgWith(1, null, @status = "failure")
@CompileManager.compile @project_id, @user_id, {}, @callback
it "should call the callback", ->
@callback
.calledWith(null, @status)
.should.equal true
it "should clear the CLSI cache", ->
@ClsiManager.deleteAuxFiles
.calledWith(@project_id)
.should.equal true
describe "when the project has been recently compiled", ->
beforeEach ->