File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
src/api/integrations/channel/whatsapp Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments