mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Extract method to add common params
This commit is contained in:
parent
07b0f37579
commit
f2fc999ce4
1 changed files with 21 additions and 14 deletions
|
@ -5,6 +5,20 @@ request = require "requestretry"
|
||||||
Errors = require '../Errors/Errors'
|
Errors = require '../Errors/Errors'
|
||||||
|
|
||||||
|
|
||||||
|
makeFaultTolerantRequest = (userId, options, callback) ->
|
||||||
|
if userId+"" == settings.smokeTest?.userId+""
|
||||||
|
return callback()
|
||||||
|
|
||||||
|
options = Object.assign(options, {
|
||||||
|
delayStrategy: exponentialBackoffStrategy()
|
||||||
|
timeout: 1000
|
||||||
|
})
|
||||||
|
|
||||||
|
if settings.overleaf?
|
||||||
|
options.qs = Object.assign({}, options.qs, { fromV2: 1 })
|
||||||
|
|
||||||
|
makeRequest(options, callback)
|
||||||
|
|
||||||
makeRequest = (opts, callback)->
|
makeRequest = (opts, callback)->
|
||||||
if settings.apis?.analytics?.url?
|
if settings.apis?.analytics?.url?
|
||||||
urlPath = opts.url
|
urlPath = opts.url
|
||||||
|
@ -49,40 +63,33 @@ module.exports =
|
||||||
makeRequest opts, callback
|
makeRequest opts, callback
|
||||||
|
|
||||||
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
|
recordEvent: (user_id, event, segmentation = {}, callback = (error) ->) ->
|
||||||
if user_id+"" == settings.smokeTest?.userId+""
|
|
||||||
return callback()
|
|
||||||
opts =
|
opts =
|
||||||
body:
|
body:
|
||||||
event:event
|
event:event
|
||||||
segmentation:segmentation
|
segmentation:segmentation
|
||||||
json:true
|
json:true
|
||||||
method:"POST"
|
method:"POST"
|
||||||
timeout:1000
|
|
||||||
url: "/user/#{user_id}/event"
|
url: "/user/#{user_id}/event"
|
||||||
delayStrategy: exponentialBackoffStrategy()
|
|
||||||
maxAttempts: 7 # Give up after ~ 8min
|
maxAttempts: 7 # Give up after ~ 8min
|
||||||
if settings.overleaf?
|
|
||||||
opts.qs = {fromV2: 1}
|
makeFaultTolerantRequest user_id, opts, callback
|
||||||
makeRequest opts, callback
|
|
||||||
|
|
||||||
updateEditingSession: (userId, projectId, countryCode, callback = (error) ->) ->
|
updateEditingSession: (userId, projectId, countryCode, callback = (error) ->) ->
|
||||||
if userId+"" == settings.smokeTest?.userId+""
|
|
||||||
return callback()
|
|
||||||
query =
|
query =
|
||||||
userId: userId
|
userId: userId
|
||||||
projectId: projectId
|
projectId: projectId
|
||||||
|
|
||||||
if countryCode
|
if countryCode
|
||||||
query.countryCode = countryCode
|
query.countryCode = countryCode
|
||||||
|
|
||||||
opts =
|
opts =
|
||||||
method: "PUT"
|
method: "PUT"
|
||||||
timeout: 1000
|
|
||||||
url: "/editingSession"
|
url: "/editingSession"
|
||||||
qs: query
|
qs: query
|
||||||
maxAttempts: 6 # Give up after ~ 4min
|
maxAttempts: 6 # Give up after ~ 4min
|
||||||
delayStrategy: exponentialBackoffStrategy()
|
|
||||||
if settings.overleaf?
|
makeFaultTolerantRequest userId, opts, callback
|
||||||
opts.qs.fromV2 = 1
|
|
||||||
makeRequest opts, callback
|
|
||||||
|
|
||||||
|
|
||||||
getLastOccurrence: (user_id, event, callback = (error) ->) ->
|
getLastOccurrence: (user_id, event, callback = (error) ->) ->
|
||||||
|
|
Loading…
Reference in a new issue