mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-09 09:59:40 -06:00
check cronId before executing syncChatwootLostMessages
This commit is contained in:
parent
c2085b59ea
commit
43cc6d3608
@ -4357,7 +4357,18 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const prepare = (message: any) => this.prepareMessage(message);
|
||||
this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare);
|
||||
|
||||
// Generate ID for this cron task and store in cache
|
||||
const cronId = cuid();
|
||||
const cronKey = `chatwoot:syncLostMessages`;
|
||||
await this.chatwootService.getCache()?.hSet(cronKey, this.instance.name, cronId);
|
||||
|
||||
const task = cron.schedule('0,30 * * * *', async () => {
|
||||
// Check ID before executing (only if cache is available)
|
||||
const cache = this.chatwootService.getCache();
|
||||
if (cache) {
|
||||
const storedId = await cache.hGet(cronKey, this.instance.name);
|
||||
if (storedId && storedId !== cronId) return;
|
||||
}
|
||||
this.chatwootService.syncLostMessages({ instanceName: this.instance.name }, chatwootConfig, prepare);
|
||||
});
|
||||
task.start();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user