Skip to content

Commit 05886ec

Browse files
committed
feat: enhance message processing with retry logic for error handling
1 parent 89d4d34 commit 05886ec

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/api/integrations/channel/whatsapp/baileysMessage.processor.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Logger } from '@config/logger.config';
22
import { BaileysEventMap, MessageUpsertType, proto } from 'baileys';
3-
import { catchError, concatMap, EMPTY, from, Subject, Subscription, tap } from 'rxjs';
3+
import { catchError, concatMap, delay, EMPTY, from, retryWhen, Subject, Subscription, take, tap } from 'rxjs';
44

55
type MessageUpsertPayload = BaileysEventMap['messages.upsert'];
66
type MountProps = {
@@ -25,7 +25,15 @@ export class BaileysMessageProcessor {
2525
this.processorLogs.log(`Processing batch of ${messages.length} messages`);
2626
}),
2727
concatMap(({ messages, type, requestId, settings }) =>
28-
from(onMessageReceive({ messages, type, requestId }, settings)),
28+
from(onMessageReceive({ messages, type, requestId }, settings)).pipe(
29+
retryWhen((errors) =>
30+
errors.pipe(
31+
tap((error) => this.processorLogs.warn(`Retrying message batch due to error: ${error.message}`)),
32+
delay(1000), // 1 segundo de delay
33+
take(3), // Máximo 3 tentativas
34+
),
35+
),
36+
),
2937
),
3038
catchError((error) => {
3139
this.processorLogs.error(`Error processing message batch: ${error}`);

0 commit comments

Comments
 (0)