feat: enhance message processing with retry logic for error handling

This commit is contained in:
Santosl2 2025-07-15 21:41:25 -03:00
parent 89d4d341f6
commit 05886ec684
No known key found for this signature in database
GPG Key ID: 6D81780D2C0364A0

View File

@ -1,6 +1,6 @@
import { Logger } from '@config/logger.config';
import { BaileysEventMap, MessageUpsertType, proto } from 'baileys';
import { catchError, concatMap, EMPTY, from, Subject, Subscription, tap } from 'rxjs';
import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs';
type MessageUpsertPayload = BaileysEventMap['messages.upsert'];
type MountProps = {
@ -25,7 +25,15 @@ export class BaileysMessageProcessor {
this.processorLogs.log(`Processing batch of ${messages.length} messages`);
}),
concatMap(({ messages, type, requestId, settings }) =>
from(onMessageReceive({ messages, type, requestId }, settings)),
from(onMessageReceive({ messages, type, requestId }, settings)).pipe(
retryWhen((errors) =>
errors.pipe(
tap((error) => this.processorLogs.warn(`Retrying message batch due to error: ${error.message}`)),
delay(1000), // 1 segundo de delay
take(3), // Máximo 3 tentativas
),
),
),
),
catchError((error) => {
this.processorLogs.error(`Error processing message batch: ${error}`);