From 4518142497a8b72b2df95f6b576720602afd6f0c Mon Sep 17 00:00:00 2001 From: Pedro Howat Date: Fri, 6 Sep 2024 13:12:28 -0300 Subject: [PATCH] never delete instances automatically --- src/api/services/monitor.service.ts | 89 +++++++++++++++-------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index 9b7809d9..abef9042 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -10,7 +10,7 @@ import { CacheConf, ConfigService, Database, - DelInstance, + // DelInstance, HttpServer, ProviderSession, } from '../../config/env.config'; @@ -71,28 +71,30 @@ export class WAMonitoringService { private readonly providerSession = Object.freeze(this.configService.get('PROVIDER')); public delInstanceTime(instance: string) { - const time = this.configService.get('DEL_INSTANCE'); - if (typeof time === 'number' && time > 0) { - this.logger.verbose(`Instance "${instance}" don't have connection, will be removed in ${time} minutes`); + this.logger.verbose(instance); + return; // Never delete instance on timeouts + // const time = this.configService.get('DEL_INSTANCE'); + // if (typeof time === 'number' && time > 0) { + // this.logger.verbose(`Instance "${instance}" don't have connection, will be removed in ${time} minutes`); - setTimeout(async () => { - if (this.waInstances[instance]?.connectionStatus?.state !== 'open') { - if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') { - if ((await this.waInstances[instance].findIntegration()).integration === Integration.WHATSAPP_BAILEYS) { - await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance); - this.waInstances[instance]?.client?.ws?.close(); - this.waInstances[instance]?.client?.end(undefined); - } - this.waInstances[instance]?.removeRabbitmqQueues(); - delete this.waInstances[instance]; - } else { - this.waInstances[instance]?.removeRabbitmqQueues(); - delete this.waInstances[instance]; - this.eventEmitter.emit('remove.instance', instance, 'inner'); - } - } - }, 1000 * 60 * time); - } + // setTimeout(async () => { + // if (this.waInstances[instance]?.connectionStatus?.state !== 'open') { + // if (this.waInstances[instance]?.connectionStatus?.state === 'connecting') { + // if ((await this.waInstances[instance].findIntegration()).integration === Integration.WHATSAPP_BAILEYS) { + // await this.waInstances[instance]?.client?.logout('Log out instance: ' + instance); + // this.waInstances[instance]?.client?.ws?.close(); + // this.waInstances[instance]?.client?.end(undefined); + // } + // this.waInstances[instance]?.removeRabbitmqQueues(); + // delete this.waInstances[instance]; + // } else { + // this.waInstances[instance]?.removeRabbitmqQueues(); + // delete this.waInstances[instance]; + // this.eventEmitter.emit('remove.instance', instance, 'inner'); + // } + // } + // }, 1000 * 60 * time); + // } } public async instanceInfo(instanceName?: string, arrayReturn = false) { @@ -517,25 +519,28 @@ export class WAMonitoringService { } private async deleteTempInstances(collections: Collection[]) { - const shouldDelete = this.configService.get('DEL_TEMP_INSTANCES'); - if (!shouldDelete) { - this.logger.verbose('Temp instances deletion is disabled'); - return; - } - this.logger.verbose('Cleaning up temp instances'); - const auths = await this.repository.auth.list(); - if (auths.length === 0) { - this.logger.verbose('No temp instances found'); - return; - } - let tempInstances = 0; - auths.forEach((auth) => { - if (collections.find((coll) => coll.namespace.replace(/^[\w-]+\./, '') === auth._id)) { - return; - } - tempInstances++; - this.eventEmitter.emit('remove.instance', auth._id, 'inner'); - }); - this.logger.verbose('Temp instances removed: ' + tempInstances); + this.logger.verbose(collections); + return; // Never delete temp instances + + // const shouldDelete = this.configService.get('DEL_TEMP_INSTANCES'); + // if (!shouldDelete) { + // this.logger.verbose('Temp instances deletion is disabled'); + // return; + // } + // this.logger.verbose('Cleaning up temp instances'); + // const auths = await this.repository.auth.list(); + // if (auths.length === 0) { + // this.logger.verbose('No temp instances found'); + // return; + // } + // let tempInstances = 0; + // auths.forEach((auth) => { + // if (collections.find((coll) => coll.namespace.replace(/^[\w-]+\./, '') === auth._id)) { + // return; + // } + // tempInstances++; + // this.eventEmitter.emit('remove.instance', auth._id, 'inner'); + // }); + // this.logger.verbose('Temp instances removed: ' + tempInstances); } }