Skip to content

Commit

Permalink
Merge pull request #357 from AppQuality/develop
Browse files Browse the repository at this point in the history
feat: Use exponential wait for completition
  • Loading branch information
d-beezee authored Oct 23, 2024
2 parents 8c7371e + db4fb28 commit b555c19
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/features/paypal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import debugMessage from "../debugMessage";

dotenv.config();

const DEFAULT_RETRIES = 10;

class Paypal {
clientId: string;
secret: string;
Expand Down Expand Up @@ -197,7 +199,7 @@ class Paypal {

private async waitForCompletion(
requestUrl: string,
retries = 10
retries = DEFAULT_RETRIES
): Promise<AxiosResponse["data"]> {
let token;
if (retries === 0) throw Error("Max retries reached");
Expand All @@ -219,7 +221,9 @@ class Paypal {
return res.data;
}
debugMessage(res.data.batch_header);
await new Promise((resolve) => setTimeout(resolve, 500));
await new Promise((resolve) =>
setTimeout(resolve, (DEFAULT_RETRIES + 1 - retries) * 500)
);
return this.waitForCompletion(requestUrl, retries - 1);
} catch (error) {
throw error;
Expand Down

0 comments on commit b555c19

Please sign in to comment.