Skip to content

Commit a2c25bb

Browse files
feat(webhook): adicionar interface para configuração de timeout e retry
Adiciona interface de configuração na estrutura Webhook para permitir: - Configuração de timeout em requisições - Parâmetros de retentativas configuráveis - Lista de códigos HTTP que não devem gerar retry Issue: #1325
1 parent 427c994 commit a2c25bb

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/config/env.config.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,21 @@ export type CacheConfLocal = {
220220
TTL: number;
221221
};
222222
export type SslConf = { PRIVKEY: string; FULLCHAIN: string };
223-
export type Webhook = { GLOBAL?: GlobalWebhook; EVENTS: EventsWebhook };
223+
export type Webhook = {
224+
GLOBAL?: GlobalWebhook;
225+
EVENTS: EventsWebhook;
226+
REQUEST?: {
227+
TIMEOUT_MS?: number;
228+
};
229+
RETRY?: {
230+
MAX_ATTEMPTS?: number;
231+
INITIAL_DELAY_SECONDS?: number;
232+
USE_EXPONENTIAL_BACKOFF?: boolean;
233+
MAX_DELAY_SECONDS?: number;
234+
JITTER_FACTOR?: number;
235+
NON_RETRYABLE_STATUS_CODES?: number[];
236+
};
237+
};
224238
export type Pusher = { ENABLED: boolean; GLOBAL?: GlobalPusher; EVENTS: EventsPusher };
225239
export type ConfigSessionPhone = { CLIENT: string; NAME: string; VERSION: string };
226240
export type QrCode = { LIMIT: number; COLOR: string };
@@ -497,6 +511,17 @@ export class ConfigService {
497511
ERRORS: process.env?.WEBHOOK_EVENTS_ERRORS === 'true',
498512
ERRORS_WEBHOOK: process.env?.WEBHOOK_EVENTS_ERRORS_WEBHOOK || '',
499513
},
514+
REQUEST: {
515+
TIMEOUT_MS: Number.parseInt(process.env?.WEBHOOK_REQUEST_TIMEOUT_MS) || 30000,
516+
},
517+
RETRY: {
518+
MAX_ATTEMPTS: Number.parseInt(process.env?.WEBHOOK_RETRY_MAX_ATTEMPTS) || 10,
519+
INITIAL_DELAY_SECONDS: Number.parseInt(process.env?.WEBHOOK_RETRY_INITIAL_DELAY_SECONDS) || 5,
520+
USE_EXPONENTIAL_BACKOFF: process.env?.WEBHOOK_RETRY_USE_EXPONENTIAL_BACKOFF !== 'false',
521+
MAX_DELAY_SECONDS: Number.parseInt(process.env?.WEBHOOK_RETRY_MAX_DELAY_SECONDS) || 300,
522+
JITTER_FACTOR: Number.parseFloat(process.env?.WEBHOOK_RETRY_JITTER_FACTOR) || 0.2,
523+
NON_RETRYABLE_STATUS_CODES: process.env?.WEBHOOK_RETRY_NON_RETRYABLE_STATUS_CODES?.split(',').map(Number) || [400, 401, 403, 404, 422],
524+
},
500525
},
501526
CONFIG_SESSION_PHONE: {
502527
CLIENT: process.env?.CONFIG_SESSION_PHONE_CLIENT || 'Evolution API',

0 commit comments

Comments
 (0)