mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Use requestretry
node package
This commit is contained in:
parent
8117061674
commit
0efc8136cb
3 changed files with 17 additions and 18 deletions
|
@ -1,29 +1,15 @@
|
|||
settings = require "settings-sharelatex"
|
||||
logger = require "logger-sharelatex"
|
||||
_ = require "underscore"
|
||||
request = require "request"
|
||||
request = require "requestretry"
|
||||
Errors = require '../Errors/Errors'
|
||||
|
||||
|
||||
makeRequest = (opts, callback)->
|
||||
retryTimings = [1, 2, 4, 8, 16, 32, 32, 32]
|
||||
if settings.apis?.analytics?.url?
|
||||
urlPath = opts.url
|
||||
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
|
||||
iteration = 0
|
||||
_go = () ->
|
||||
request opts, (err, response, data) ->
|
||||
if err?
|
||||
if iteration == retryTimings.length or !opts.retryOnFail
|
||||
logger.err {err, url: opts.url},
|
||||
"Error in analytics request, retries failed"
|
||||
return callback(err)
|
||||
backoffSeconds = retryTimings[iteration]
|
||||
iteration += 1
|
||||
setTimeout(_go, backoffSeconds * 1000)
|
||||
else
|
||||
callback(null, response, data)
|
||||
_go()
|
||||
request opts, callback
|
||||
else
|
||||
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|
||||
|
||||
|
@ -51,7 +37,8 @@ module.exports =
|
|||
method:"POST"
|
||||
timeout:1000
|
||||
url: "/user/#{user_id}/event"
|
||||
retryOnFail: true
|
||||
maxAttempts: 20
|
||||
retryDelay: 5000
|
||||
if settings.overleaf?
|
||||
opts.qs = {fromV2: 1}
|
||||
makeRequest opts, callback
|
||||
|
@ -69,7 +56,8 @@ module.exports =
|
|||
qs:
|
||||
userId: userId
|
||||
projectId: projectId
|
||||
retryOnFail: true
|
||||
maxAttempts: 20
|
||||
retryDelay: 5000
|
||||
if settings.overleaf?
|
||||
opts.qs.fromV2 = 1
|
||||
makeRequest opts, callback
|
||||
|
|
10
services/web/npm-shrinkwrap.json
generated
10
services/web/npm-shrinkwrap.json
generated
|
@ -6926,6 +6926,11 @@
|
|||
"from": "request@>=2.69.0 <3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/request/-/request-2.83.0.tgz"
|
||||
},
|
||||
"requestretry": {
|
||||
"version": "1.13.0",
|
||||
"from": "requestretry@latest",
|
||||
"resolved": "https://registry.npmjs.org/requestretry/-/requestretry-1.13.0.tgz"
|
||||
},
|
||||
"requests": {
|
||||
"version": "0.1.7",
|
||||
"from": "requests@>=0.1.7 <0.2.0",
|
||||
|
@ -9309,6 +9314,11 @@
|
|||
"resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz",
|
||||
"dev": true
|
||||
},
|
||||
"when": {
|
||||
"version": "3.7.8",
|
||||
"from": "when@>=3.7.7 <4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/when/-/when-3.7.8.tgz"
|
||||
},
|
||||
"which": {
|
||||
"version": "1.0.9",
|
||||
"from": "which@>=1.0.5 <1.1.0",
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
"pug": "^2.0.0-beta6",
|
||||
"redis-sharelatex": "git+https://github.com/sharelatex/redis-sharelatex.git#v1.0.4",
|
||||
"request": "^2.69.0",
|
||||
"requestretry": "^1.13.0",
|
||||
"requests": "^0.1.7",
|
||||
"rimraf": "2.2.6",
|
||||
"rolling-rate-limiter": "git+https://github.com/ShaneKilkelly/rolling-rate-limiter.git#master",
|
||||
|
|
Loading…
Reference in a new issue