mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #1256 from sharelatex/sk-file-upload-retry
Add a retry around `FileStoreHandler.uploadFileFromDisk` GitOrigin-RevId: 2fc54036acdeda15c00a3d0222fd1a83683a5798
This commit is contained in:
parent
362c1f64db
commit
c423e483ba
2 changed files with 12 additions and 0 deletions
|
@ -2,12 +2,15 @@ logger = require("logger-sharelatex")
|
|||
fs = require("fs")
|
||||
request = require("request")
|
||||
settings = require("settings-sharelatex")
|
||||
Async = require('async')
|
||||
|
||||
oneMinInMs = 60 * 1000
|
||||
fiveMinsInMs = oneMinInMs * 5
|
||||
|
||||
module.exports = FileStoreHandler =
|
||||
|
||||
RETRY_ATTEMPTS: 3
|
||||
|
||||
uploadFileFromDisk: (project_id, file_id, fsPath, callback)->
|
||||
fs.lstat fsPath, (err, stat)->
|
||||
if err?
|
||||
|
@ -19,7 +22,14 @@ module.exports = FileStoreHandler =
|
|||
if !stat.isFile()
|
||||
logger.log project_id:project_id, file_id:file_id, fsPath:fsPath, "tried to upload symlink, not contining"
|
||||
return callback(new Error("can not upload symlink"))
|
||||
Async.retry FileStoreHandler.RETRY_ATTEMPTS, (cb) ->
|
||||
FileStoreHandler._doUploadFileFromDisk project_id, file_id, fsPath, cb
|
||||
, (err, url) ->
|
||||
if err?
|
||||
logger.err {err, project_id, file_id}, "Error uploading file, retries failed"
|
||||
callback(err, url)
|
||||
|
||||
_doUploadFileFromDisk: (project_id, file_id, fsPath, callback) ->
|
||||
_cb = callback
|
||||
callback = (err, url) ->
|
||||
callback = -> # avoid double callbacks
|
||||
|
|
|
@ -115,6 +115,7 @@ describe "FileStoreHandler", ->
|
|||
cb({statusCode: 500})
|
||||
|
||||
it 'should callback with an error', (done) ->
|
||||
@fs.createReadStream.callCount = 0
|
||||
@fs.createReadStream.returns
|
||||
pipe:->
|
||||
on: (type, cb)->
|
||||
|
@ -123,6 +124,7 @@ describe "FileStoreHandler", ->
|
|||
@handler.uploadFileFromDisk @project_id, @file_id, @fsPath, (err) =>
|
||||
expect(err).to.exist
|
||||
expect(err).to.be.instanceof Error
|
||||
expect(@fs.createReadStream.callCount).to.equal @handler.RETRY_ATTEMPTS
|
||||
done()
|
||||
|
||||
describe "deleteFile", ->
|
||||
|
|
Loading…
Reference in a new issue