fix handler_org and remove retry
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 1m10s
This commit is contained in:
parent
ac6b487d66
commit
7827e19254
2 changed files with 34 additions and 25 deletions
|
|
@ -92,8 +92,6 @@ export async function init() {
|
|||
// createConsumer(queue2, channel, handler2);
|
||||
}
|
||||
|
||||
let retries = 0;
|
||||
|
||||
function createConsumer( //----> consumer
|
||||
queue: string,
|
||||
channel: amqp.Channel,
|
||||
|
|
@ -103,13 +101,15 @@ function createConsumer( //----> consumer
|
|||
queue,
|
||||
async (msg) => {
|
||||
if (!msg) return;
|
||||
if ((await handler(msg)) || retries++ >= 3) {
|
||||
retries = 0;
|
||||
try {
|
||||
await handler(msg);
|
||||
console.log("[AMQ] Process Consumer success");
|
||||
} catch (error) {
|
||||
console.log("[AMQ] Process Consumer failed");
|
||||
} finally {
|
||||
// Always acknowledge - no retries
|
||||
return channel.ack(msg);
|
||||
}
|
||||
console.log("[AMQ] Process Consumer failed");
|
||||
return await new Promise((resolve) => setTimeout(() => resolve(channel.nack(msg)), 3000));
|
||||
},
|
||||
{ noAck: false },
|
||||
);
|
||||
|
|
@ -1963,7 +1963,7 @@ async function handler_org(msg: amqp.ConsumeMessage): Promise<boolean> {
|
|||
).catch(console.error);
|
||||
}
|
||||
console.timeEnd('[AMQ] handler_org_total');
|
||||
return false; // ✅ Return false to prevent RabbitMQ retry
|
||||
throw error; // ✅ Re-throw to be caught by createConsumer's try-catch
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue