add retry count

This commit is contained in:
arc-alex
2023-12-05 21:28:37 +01:00
parent 0523a68ef4
commit d0191ebc26
5 changed files with 21 additions and 5 deletions
+1
View File
@@ -59,6 +59,7 @@ export const dbModel: DatabaseModel = {
},
http: {
enabledOut: false,
retryCount: 0,
subscriptions: {
onLoad: [],
onStart: [],
@@ -17,7 +17,7 @@ type Action = TimerLifeCycleKey | string;
export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
// protected httpAgent: null | http.Agent;
subscriptions: HttpSubscription;
private retryCount = 0;
constructor() {
// this.httpAgent = null;
this.subscriptions = dbModel.http.subscriptions;
@@ -27,7 +27,9 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
* Initializes httpClient
*/
init(config: HttpSettings) {
const { subscriptions, enabledOut } = config;
const { subscriptions, enabledOut, retryCount } = config;
this.retryCount = retryCount;
if (!enabledOut) {
// this.httpAgent?.destroy();
@@ -102,12 +104,12 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
if (method === 'GET') {
await got.get(path, {
searchParams: options,
retry: { limit: 0 },
retry: { limit: this.retryCount },
});
} else if (method === 'POST') {
await got.post(path, {
body: options,
retry: { limit: 0 },
retry: { limit: this.retryCount },
});
}
} catch (err) {
+3
View File
@@ -280,8 +280,11 @@ export const parseHttp = (data: { http?: Partial<HttpSettings> }): HttpSettings
? loadedConfig.subscriptions
: dbModel.http.subscriptions;
const retryCount = Math.max(0, loadedConfig.retryCount ?? dbModel.http.retryCount);
return {
enabledOut: loadedConfig.enabledOut ?? dbModel.http.enabledOut,
retryCount: retryCount,
subscriptions: validatedSubscriptions,
};
}