mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-07 02:10:39 +00:00
priority compiles are proxyed to the priority servers
This commit is contained in:
parent
36136a99ca
commit
250606472d
2 changed files with 62 additions and 22 deletions
|
@ -64,10 +64,17 @@ module.exports = CompileController =
|
|||
|
||||
proxyToClsi: (url, req, res, next = (error) ->) ->
|
||||
logger.log url: url, "proxying to CLSI"
|
||||
url = "#{Settings.apis.clsi.url}#{url}"
|
||||
oneMinute = 60 * 1000
|
||||
proxy = request(url: url, method: req.method, timeout: oneMinute)
|
||||
proxy.pipe(res)
|
||||
proxy.on "error", (error) ->
|
||||
logger.warn err: error, url: url, "CLSI proxy error"
|
||||
|
||||
AuthenticationController.getLoggedInUserId req, (error, user_id) ->
|
||||
|
||||
UserGetter.getUser user_id, {"features.compileGroup":1, "features.compileTimeout":1}, (err, user)->
|
||||
if user.features?.compileGroup == "priority"
|
||||
compilerUrl = Settings.apis.clsi_priority.url
|
||||
else
|
||||
compilerUrl = Settings.apis.clsi.url
|
||||
url = "#{compilerUrl}#{url}"
|
||||
oneMinute = 60 * 1000
|
||||
proxy = request(url: url, method: req.method, timeout: oneMinute)
|
||||
proxy.pipe(res)
|
||||
proxy.on "error", (error) ->
|
||||
logger.warn err: error, url: url, "CLSI proxy error"
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ describe "CompileController", ->
|
|||
apis:
|
||||
clsi:
|
||||
url: "clsi.example.com"
|
||||
clsi_priority:
|
||||
url: "clsi-priority.example.com"
|
||||
"request": @request = sinon.stub()
|
||||
"../../models/Project": Project: @Project = {}
|
||||
"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
|
||||
|
@ -145,24 +147,50 @@ describe "CompileController", ->
|
|||
statusCode: 204
|
||||
headers: { "mock": "header" }
|
||||
@req.method = "mock-method"
|
||||
@CompileController.proxyToClsi(@url = "/test", @req, @res, @next)
|
||||
@AuthenticationController.getLoggedInUserId = sinon.stub().callsArgWith(1, null, @user_id = "mock-user-id")
|
||||
|
||||
|
||||
describe "user with standard priority", ->
|
||||
|
||||
beforeEach ->
|
||||
@UserGetter.getUser.callsArgWith(2, null, @user)
|
||||
@CompileController.proxyToClsi(@url = "/test", @req, @res, @next)
|
||||
|
||||
it "should open a request to the CLSI", ->
|
||||
@request
|
||||
.calledWith(
|
||||
method: @req.method
|
||||
url: "#{@settings.apis.clsi.url}#{@url}",
|
||||
timeout: 60 * 1000
|
||||
)
|
||||
.should.equal true
|
||||
|
||||
it "should pass the request on to the client", ->
|
||||
@proxy.pipe
|
||||
.calledWith(@res)
|
||||
.should.equal true
|
||||
|
||||
it "should bind an error handle to the request proxy", ->
|
||||
@proxy.on.calledWith("error").should.equal true
|
||||
|
||||
describe "user with priority compile", ->
|
||||
|
||||
beforeEach ->
|
||||
@user.features.compileGroup = "priority"
|
||||
@UserGetter.getUser.callsArgWith(2, null, @user)
|
||||
@CompileController.proxyToClsi(@url = "/test", @req, @res, @next)
|
||||
|
||||
it "should proxy to the priorty url if the user has the feature", ()->
|
||||
@request
|
||||
.calledWith(
|
||||
method: @req.method
|
||||
url: "#{@settings.apis.clsi_priority.url}#{@url}",
|
||||
timeout: 60 * 1000
|
||||
)
|
||||
.should.equal true
|
||||
|
||||
it "should open a request to the CLSI", ->
|
||||
@request
|
||||
.calledWith(
|
||||
method: @req.method
|
||||
url: "#{@settings.apis.clsi.url}#{@url}",
|
||||
timeout: 60 * 1000
|
||||
)
|
||||
.should.equal true
|
||||
|
||||
it "should pass the request on to the client", ->
|
||||
@proxy.pipe
|
||||
.calledWith(@res)
|
||||
.should.equal true
|
||||
|
||||
it "should bind an error handle to the request proxy", ->
|
||||
@proxy.on.calledWith("error").should.equal true
|
||||
|
||||
describe "deleteAuxFiles", ->
|
||||
beforeEach ->
|
||||
|
@ -201,3 +229,8 @@ describe "CompileController", ->
|
|||
@CompileController.compileAndDownloadPdf @req, @res
|
||||
@CompileController.proxyToClsi.calledWith("/project/#{@project_id}/output/output.pdf", @req, @res).should.equal true
|
||||
done()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue