File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
src/api/integrations/channel/whatsapp Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -4385,7 +4385,22 @@ export class BaileysStartupService extends ChannelStartupService {
43854385 const prepare = ( message : any ) => this . prepareMessage ( message ) ;
43864386 this . chatwootService . syncLostMessages ( { instanceName : this . instance . name } , chatwootConfig , prepare ) ;
43874387
4388+ // Generate ID for this cron task and store in cache
4389+ const cronId = cuid ( ) ;
4390+ const cronKey = `chatwoot:syncLostMessages` ;
4391+ await this . chatwootService . getCache ( ) ?. hSet ( cronKey , this . instance . name , cronId ) ;
4392+
43884393 const task = cron . schedule ( '0,30 * * * *' , async ( ) => {
4394+ // Check ID before executing (only if cache is available)
4395+ const cache = this . chatwootService . getCache ( ) ;
4396+ if ( cache ) {
4397+ const storedId = await cache . hGet ( cronKey , this . instance . name ) ;
4398+ if ( storedId && storedId !== cronId ) {
4399+ this . logger . info ( `Stopping syncChatwootLostMessages cron - ID mismatch: ${ cronId } vs ${ storedId } ` ) ;
4400+ task . stop ( ) ;
4401+ return ;
4402+ }
4403+ }
43894404 this . chatwootService . syncLostMessages ( { instanceName : this . instance . name } , chatwootConfig , prepare ) ;
43904405 } ) ;
43914406 task . start ( ) ;
You can’t perform that action at this time.
0 commit comments