feat: use exponential backoff delay by default

Use exponential backoff delay by default

commit-id:e0f13cf2
This commit is contained in:
Conicaw 2023-12-23 17:59:25 -06:00
parent 26a547ead3
commit d5bdf16c67
No known key found for this signature in database
GPG key ID: 8DE10AC00159C418

View file

@ -2,7 +2,7 @@ import type { DynamicModule, Provider } from '@nestjs/common';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util'; import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
import axios from 'axios'; import axios from 'axios';
import axiosRetry from 'axios-retry'; import axiosRetry, { exponentialDelay } from 'axios-retry';
import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants'; import { AXIOS_INSTANCE_TOKEN, HTTP_MODULE_ID, HTTP_MODULE_OPTIONS } from './http.constants';
import { HttpService } from './http.service'; import { HttpService } from './http.service';
@ -14,7 +14,11 @@ import type {
const createAxiosInstance = (config?: HttpModuleOptions) => { const createAxiosInstance = (config?: HttpModuleOptions) => {
const axiosInstance = axios.create(config); const axiosInstance = axios.create(config);
axiosRetry(axiosInstance, config); axiosRetry(axiosInstance, {
// Default exponential backoff
retryDelay: exponentialDelay,
...config,
});
return axiosInstance; return axiosInstance;
}; };