rate-limit concurrent processPreCoin
This commit is contained in:
parent
d088aec009
commit
86fb71f563
@ -379,6 +379,8 @@ export class Wallet {
|
||||
private notifier: Notifier;
|
||||
public cryptoApi: CryptoApi;
|
||||
|
||||
private processPreCoinConcurrent = 0;
|
||||
|
||||
/**
|
||||
* Set of identifiers for running operations.
|
||||
*/
|
||||
@ -725,8 +727,16 @@ export class Wallet {
|
||||
|
||||
|
||||
private async processPreCoin(preCoin: PreCoinRecord,
|
||||
retryDelayMs = 100): Promise<void> {
|
||||
|
||||
retryDelayMs = 200): Promise<void> {
|
||||
if (this.processPreCoinConcurrent >= 1) {
|
||||
console.log("delaying processPreCoin");
|
||||
setTimeout(() => this.processPreCoin(preCoin, retryDelayMs * 2),
|
||||
retryDelayMs);
|
||||
return;
|
||||
}
|
||||
console.log("executing processPreCoin");
|
||||
this.processPreCoinConcurrent++;
|
||||
try {
|
||||
const exchange = await this.q().get(Stores.exchanges,
|
||||
preCoin.exchangeBaseUrl);
|
||||
if (!exchange) {
|
||||
@ -740,7 +750,6 @@ export class Wallet {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const coin = await this.withdrawExecute(preCoin);
|
||||
|
||||
const mutateReserve = (r: ReserveRecord) => {
|
||||
@ -784,6 +793,8 @@ export class Wallet {
|
||||
let nextRetryDelayMs = Math.min(retryDelayMs * 2, 1000 * 60);
|
||||
setTimeout(() => this.processPreCoin(preCoin, nextRetryDelayMs),
|
||||
retryDelayMs);
|
||||
} finally {
|
||||
this.processPreCoinConcurrent--;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user