diff --git a/services/web/app/coffee/Features/Compile/ClsiManager.coffee b/services/web/app/coffee/Features/Compile/ClsiManager.coffee index 08ef23bcd8..35b49881ac 100755 --- a/services/web/app/coffee/Features/Compile/ClsiManager.coffee +++ b/services/web/app/coffee/Features/Compile/ClsiManager.coffee @@ -10,6 +10,7 @@ ClsiCookieManager = require("./ClsiCookieManager") _ = require("underscore") async = require("async") ClsiFormatChecker = require("./ClsiFormatChecker") +DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler" module.exports = ClsiManager = @@ -109,48 +110,50 @@ module.exports = ClsiManager = if project.compiler not in ClsiManager.VALID_COMPILERS project.compiler = "pdflatex" - ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) -> + DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> return callback(error) if error? - ProjectEntityHandler.getAllFiles project_id, (error, files = {}) -> + ProjectEntityHandler.getAllDocs project_id, (error, docs = {}) -> return callback(error) if error? + ProjectEntityHandler.getAllFiles project_id, (error, files = {}) -> + return callback(error) if error? - resources = [] - rootResourcePath = null - rootResourcePathOverride = null + resources = [] + rootResourcePath = null + rootResourcePathOverride = null - for path, doc of docs - path = path.replace(/^\//, "") # Remove leading / - resources.push - path: path - content: doc.lines.join("\n") - if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString() - rootResourcePath = path - if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() - rootResourcePathOverride = path + for path, doc of docs + path = path.replace(/^\//, "") # Remove leading / + resources.push + path: path + content: doc.lines.join("\n") + if project.rootDoc_id? and doc._id.toString() == project.rootDoc_id.toString() + rootResourcePath = path + if options.rootDoc_id? and doc._id.toString() == options.rootDoc_id.toString() + rootResourcePathOverride = path - rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? - if !rootResourcePath? - logger.warn {project_id}, "no root document found, setting to main.tex" - rootResourcePath = "main.tex" + rootResourcePath = rootResourcePathOverride if rootResourcePathOverride? + if !rootResourcePath? + logger.warn {project_id}, "no root document found, setting to main.tex" + rootResourcePath = "main.tex" - for path, file of files - path = path.replace(/^\//, "") # Remove leading / - resources.push - path: path - url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}" - modified: file.created?.getTime() + for path, file of files + path = path.replace(/^\//, "") # Remove leading / + resources.push + path: path + url: "#{Settings.apis.filestore.url}/project/#{project._id}/file/#{file._id}" + modified: file.created?.getTime() - callback null, { - compile: - options: - compiler: project.compiler - timeout: options.timeout - imageName: project.imageName - draft: !!options.draft - check: options.check - rootResourcePath: rootResourcePath - resources: resources - } + callback null, { + compile: + options: + compiler: project.compiler + timeout: options.timeout + imageName: project.imageName + draft: !!options.draft + check: options.check + rootResourcePath: rootResourcePath + resources: resources + } wordCount: (project_id, user_id, file, options, callback = (error, response) ->) -> ClsiManager._buildRequest project_id, options, (error, req) -> diff --git a/services/web/app/coffee/Features/Compile/CompileManager.coffee b/services/web/app/coffee/Features/Compile/CompileManager.coffee index ad8a2459ec..61fe7038a6 100755 --- a/services/web/app/coffee/Features/Compile/CompileManager.coffee +++ b/services/web/app/coffee/Features/Compile/CompileManager.coffee @@ -1,7 +1,6 @@ Settings = require('settings-sharelatex') RedisWrapper = require("../../infrastructure/RedisWrapper") rclient = RedisWrapper.client("clsi_recently_compiled") -DocumentUpdaterHandler = require "../DocumentUpdater/DocumentUpdaterHandler" Project = require("../../models/Project").Project ProjectRootDocManager = require "../Project/ProjectRootDocManager" UserGetter = require "../User/UserGetter" @@ -31,19 +30,17 @@ module.exports = CompileManager = CompileManager._ensureRootDocumentIsSet project_id, (error) -> return callback(error) if error? - DocumentUpdaterHandler.flushProjectToMongo project_id, (error) -> + CompileManager.getProjectCompileLimits project_id, (error, limits) -> return callback(error) if error? - CompileManager.getProjectCompileLimits project_id, (error, limits) -> + for key, value of limits + options[key] = value + # only pass user_id down to clsi if this is a per-user compile + compileAsUser = if Settings.disablePerUserCompiles then undefined else user_id + ClsiManager.sendRequest project_id, compileAsUser, options, (error, status, outputFiles, clsiServerId, validationProblems) -> return callback(error) if error? - for key, value of limits - options[key] = value - # only pass user_id down to clsi if this is a per-user compile - compileAsUser = if Settings.disablePerUserCompiles then undefined else user_id - ClsiManager.sendRequest project_id, compileAsUser, options, (error, status, outputFiles, clsiServerId, validationProblems) -> - return callback(error) if error? - logger.log files: outputFiles, "output files" - callback(null, status, outputFiles, clsiServerId, limits, validationProblems) - + logger.log files: outputFiles, "output files" + callback(null, status, outputFiles, clsiServerId, limits, validationProblems) + stopCompile: (project_id, user_id, callback = (error) ->) -> CompileManager.getProjectCompileLimits project_id, (error, limits) -> diff --git a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee index a3eeebcaaa..6bcde76444 100644 --- a/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/ClsiManagerTests.coffee @@ -26,6 +26,7 @@ describe "ClsiManager", -> url: "https://clsipremium.example.com" "../../models/Project": Project: @Project = {} "../Project/ProjectEntityHandler": @ProjectEntityHandler = {} + "../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler = {} "./ClsiCookieManager": @ClsiCookieManager "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), warn: sinon.stub() } "request": @request = sinon.stub() @@ -144,6 +145,7 @@ describe "ClsiManager", -> @Project.findById = sinon.stub().callsArgWith(2, null, @project) @ProjectEntityHandler.getAllDocs = sinon.stub().callsArgWith(1, null, @docs) @ProjectEntityHandler.getAllFiles = sinon.stub().callsArgWith(1, null, @files) + @DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().callsArgWith(1, null) describe "with a valid project", -> beforeEach (done) -> @@ -156,6 +158,11 @@ describe "ClsiManager", -> .calledWith(@project_id, {compiler:1, rootDoc_id: 1, imageName: 1}) .should.equal true + it "should flush the project to the database", -> + @DocumentUpdaterHandler.flushProjectToMongo + .calledWith(@project_id) + .should.equal true + it "should get all the docs", -> @ProjectEntityHandler.getAllDocs .calledWith(@project_id) diff --git a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee index 3964acea41..21327a50c9 100644 --- a/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee +++ b/services/web/test/UnitTests/coffee/Compile/CompileManagerTests.coffee @@ -17,7 +17,6 @@ describe "CompileManager", -> redis: web: {host: "localhost", port: 42} "../../infrastructure/RedisWrapper": client: () => @rclient = { auth: () -> } - "../DocumentUpdater/DocumentUpdaterHandler": @DocumentUpdaterHandler = {} "../Project/ProjectRootDocManager": @ProjectRootDocManager = {} "../../models/Project": Project: @Project = {} "../User/UserGetter": @UserGetter = {} @@ -40,7 +39,6 @@ describe "CompileManager", -> beforeEach -> @CompileManager._checkIfRecentlyCompiled = sinon.stub().callsArgWith(2, null, false) @CompileManager._ensureRootDocumentIsSet = sinon.stub().callsArgWith(1, null) - @DocumentUpdaterHandler.flushProjectToMongo = sinon.stub().callsArgWith(1, null) @CompileManager.getProjectCompileLimits = sinon.stub().callsArgWith(1, null, @limits) @ClsiManager.sendRequest = sinon.stub().callsArgWith(3, null, @status = "mock-status", @outputFiles = "mock output files", @output = "mock output") @@ -54,11 +52,6 @@ describe "CompileManager", -> .calledWith(@project_id, @user_id) .should.equal true - it "should flush the project to the database", -> - @DocumentUpdaterHandler.flushProjectToMongo - .calledWith(@project_id) - .should.equal true - it "should ensure that the root document is set", -> @CompileManager._ensureRootDocumentIsSet .calledWith(@project_id)