mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add a retry to analytics requests
This commit is contained in:
parent
a06c4003f9
commit
1c15e0966c
1 changed files with 15 additions and 1 deletions
|
@ -6,10 +6,24 @@ 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}"
|
||||
request opts, callback
|
||||
iteration = 0
|
||||
_go = () ->
|
||||
request opts, (err, response, data) ->
|
||||
if err?
|
||||
if iteration == retryTimings.length
|
||||
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
|
||||
callback(new Errors.ServiceNotConfiguredError('Analytics service not configured'))
|
||||
|
||||
|
|
Loading…
Reference in a new issue