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"
|
settings = require "settings-sharelatex"
|
||||||
logger = require "logger-sharelatex"
|
logger = require "logger-sharelatex"
|
||||||
_ = require "underscore"
|
_ = require "underscore"
|
||||||
request = require "request"
|
request = require "requestretry"
|
||||||
Errors = require '../Errors/Errors'
|
Errors = require '../Errors/Errors'
|
||||||
|
|
||||||
|
|
||||||
makeRequest = (opts, callback)->
|
makeRequest = (opts, callback)->
|
||||||
retryTimings = [1, 2, 4, 8, 16, 32, 32, 32]
|
|
||||||
if settings.apis?.analytics?.url?
|
if settings.apis?.analytics?.url?
|
||||||
urlPath = opts.url
|
urlPath = opts.url
|
||||||
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
|
opts.url = "#{settings.apis.analytics.url}#{urlPath}"
|
||||||
iteration = 0
|
request opts, callback
|
||||||
_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()
|
|
||||||
else
|
else
|
||||||
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|
||||||
|
|
||||||
|
@ -51,7 +37,8 @@ module.exports =
|
||||||
method:"POST"
|
method:"POST"
|
||||||
timeout:1000
|
timeout:1000
|
||||||
url: "/user/#{user_id}/event"
|
url: "/user/#{user_id}/event"
|
||||||
retryOnFail: true
|
maxAttempts: 20
|
||||||
|
retryDelay: 5000
|
||||||
if settings.overleaf?
|
if settings.overleaf?
|
||||||
opts.qs = {fromV2: 1}
|
opts.qs = {fromV2: 1}
|
||||||
makeRequest opts, callback
|
makeRequest opts, callback
|
||||||
|
@ -69,7 +56,8 @@ module.exports =
|
||||||
qs:
|
qs:
|
||||||
userId: userId
|
userId: userId
|
||||||
projectId: projectId
|
projectId: projectId
|
||||||
retryOnFail: true
|
maxAttempts: 20
|
||||||
|
retryDelay: 5000
|
||||||
if settings.overleaf?
|
if settings.overleaf?
|
||||||
opts.qs.fromV2 = 1
|
opts.qs.fromV2 = 1
|
||||||
makeRequest opts, callback
|
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",
|
"from": "request@>=2.69.0 <3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/request/-/request-2.83.0.tgz"
|
"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": {
|
"requests": {
|
||||||
"version": "0.1.7",
|
"version": "0.1.7",
|
||||||
"from": "requests@>=0.1.7 <0.2.0",
|
"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",
|
"resolved": "https://registry.npmjs.org/websocket-extensions/-/websocket-extensions-0.1.3.tgz",
|
||||||
"dev": true
|
"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": {
|
"which": {
|
||||||
"version": "1.0.9",
|
"version": "1.0.9",
|
||||||
"from": "which@>=1.0.5 <1.1.0",
|
"from": "which@>=1.0.5 <1.1.0",
|
||||||
|
|
|
@ -71,6 +71,7 @@
|
||||||
"pug": "^2.0.0-beta6",
|
"pug": "^2.0.0-beta6",
|
||||||
"redis-sharelatex": "git+https://github.com/sharelatex/redis-sharelatex.git#v1.0.4",
|
"redis-sharelatex": "git+https://github.com/sharelatex/redis-sharelatex.git#v1.0.4",
|
||||||
"request": "^2.69.0",
|
"request": "^2.69.0",
|
||||||
|
"requestretry": "^1.13.0",
|
||||||
"requests": "^0.1.7",
|
"requests": "^0.1.7",
|
||||||
"rimraf": "2.2.6",
|
"rimraf": "2.2.6",
|
||||||
"rolling-rate-limiter": "git+https://github.com/ShaneKilkelly/rolling-rate-limiter.git#master",
|
"rolling-rate-limiter": "git+https://github.com/ShaneKilkelly/rolling-rate-limiter.git#master",
|
||||||
|
|
Loading…
Reference in a new issue