mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #2277 from overleaf/ta-recurly-script-rate-limit
Recurly Script Rate Limit GitOrigin-RevId: 726580a821daf3b3dc9c49f6739b79ddcae451b8
This commit is contained in:
parent
0def0eaa41
commit
480ca112ff
1 changed files with 20 additions and 14 deletions
|
@ -4,31 +4,37 @@ const CSVParser = require('json2csv').Parser
|
|||
|
||||
const NOW = new Date()
|
||||
|
||||
const slowCallback = (callback, error, data) =>
|
||||
setTimeout(() => callback(error, data), 80)
|
||||
|
||||
const handleAPIError = (type, account, error, callback) => {
|
||||
console.warn(
|
||||
`Errors getting ${type} for account ${account.account_code}`,
|
||||
error
|
||||
)
|
||||
if (typeof error === 'string' && error.match(/429$/)) {
|
||||
return setTimeout(callback, 1000 * 60 * 5)
|
||||
}
|
||||
slowCallback(callback)
|
||||
}
|
||||
|
||||
const getAccountSubscription = (account, callback) =>
|
||||
RecurlyWrapper.getSubscriptions(account.account_code, (error, response) => {
|
||||
if (error) {
|
||||
console.warn(
|
||||
`Errors getting subscription for account ${account.account_code}`,
|
||||
error
|
||||
)
|
||||
return callback()
|
||||
return handleAPIError('subscriptions', account, error, callback)
|
||||
}
|
||||
callback(null, response.subscriptions[0])
|
||||
slowCallback(callback, null, response.subscriptions[0])
|
||||
})
|
||||
|
||||
const isAccountUsingPaypal = (account, callback) =>
|
||||
RecurlyWrapper.getBillingInfo(account.account_code, (error, response) => {
|
||||
if (error) {
|
||||
console.warn(
|
||||
`Errors getting billing info for account ${account.account_code}`,
|
||||
error
|
||||
)
|
||||
return callback(null, false)
|
||||
return handleAPIError('billing info', account, error, callback)
|
||||
}
|
||||
if (response.billing_info.paypal_billing_agreement_id) {
|
||||
return callback(null, true)
|
||||
return slowCallback(callback, null, true)
|
||||
}
|
||||
callback(null, false)
|
||||
slowCallback(callback, null, false)
|
||||
})
|
||||
|
||||
const printAccountCSV = (account, callback) => {
|
||||
|
@ -71,7 +77,7 @@ const printAccountsCSV = callback => {
|
|||
if (error) {
|
||||
return callback(error)
|
||||
}
|
||||
async.mapLimit(accounts, 10, printAccountCSV, (error, csvData) => {
|
||||
async.mapSeries(accounts, printAccountCSV, (error, csvData) => {
|
||||
csvData = csvData.filter(d => !!d)
|
||||
callback(error, csvData)
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue