Skip to content

Commit 43cc6d3

Browse files
committed
check cronId before executing syncChatwootLostMessages
1 parent c2085b5 commit 43cc6d3

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4357,7 +4357,18 @@ export class BaileysStartupService extends ChannelStartupService {
43574357
const prepare = (message: any) => this.prepareMessage(message);
43584358
this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare);
43594359

4360+
// Generate ID for this cron task and store in cache
4361+
const cronId = cuid();
4362+
const cronKey = `chatwoot:syncLostMessages`;
4363+
await this.chatwootService.getCache()?.hSet(cronKey, this.instance.name, cronId);
4364+
43604365
const task = cron.schedule('0,30 * * * *', async () => {
4366+
// Check ID before executing (only if cache is available)
4367+
const cache = this.chatwootService.getCache();
4368+
if (cache) {
4369+
const storedId = await cache.hGet(cronKey, this.instance.name);
4370+
if (storedId && storedId !== cronId) return;
4371+
}
43614372
this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare);
43624373
});
43634374
task.start();

0 commit comments

Comments
 (0)