From a6adbd61dbe13271017ce3614ea0b58df0638acf Mon Sep 17 00:00:00 2001 From: Judson Cairo Date: Thu, 7 Mar 2024 19:26:43 -0300 Subject: [PATCH] Implemented an option to toggle temp instances deletion --- Docker/.env.example | 1 + Docker/evolution-api-all-services/.env.example | 1 + Dockerfile | 1 + src/config/env.config.ts | 4 ++++ src/dev-env.yml | 1 + src/whatsapp/services/monitor.service.ts | 5 +++++ 6 files changed, 13 insertions(+) diff --git a/Docker/.env.example b/Docker/.env.example index 5aa74a5c..53f22ceb 100644 --- a/Docker/.env.example +++ b/Docker/.env.example @@ -16,6 +16,7 @@ LOG_BAILEYS=error # Default time: 5 minutes # If you don't even want an expiration, enter the value false DEL_INSTANCE=false +DEL_TEMP_INSTANCES=true # Delete instances with status closed on start # Temporary data storage STORE_MESSAGES=true diff --git a/Docker/evolution-api-all-services/.env.example b/Docker/evolution-api-all-services/.env.example index ce71d917..a28ad50f 100644 --- a/Docker/evolution-api-all-services/.env.example +++ b/Docker/evolution-api-all-services/.env.example @@ -16,6 +16,7 @@ LOG_BAILEYS=error # Default time: 5 minutes # If you don't even want an expiration, enter the value false DEL_INSTANCE=false +DEL_TEMP_INSTANCES=true # Delete instances with status closed on start # Temporary data storage STORE_MESSAGES=true diff --git a/Dockerfile b/Dockerfile index 7758c484..03582238 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,6 +35,7 @@ ENV LOG_COLOR=true ENV LOG_BAILEYS=error ENV DEL_INSTANCE=false +ENV DEL_TEMP_INSTANCES=true ENV STORE_MESSAGES=true ENV STORE_MESSAGE_UP=true diff --git a/src/config/env.config.ts b/src/config/env.config.ts index ae4f0951..7814fc33 100644 --- a/src/config/env.config.ts +++ b/src/config/env.config.ts @@ -189,6 +189,7 @@ export interface Env { WA_BUSINESS: WaBusiness; LOG: Log; DEL_INSTANCE: DelInstance; + DEL_TEMP_INSTANCES: boolean; LANGUAGE: Language; WEBHOOK: Webhook; CONFIG_SESSION_PHONE: ConfigSessionPhone; @@ -317,6 +318,9 @@ export class ConfigService { DEL_INSTANCE: isBooleanString(process.env?.DEL_INSTANCE) ? process.env.DEL_INSTANCE === 'true' : Number.parseInt(process.env.DEL_INSTANCE) || false, + DEL_TEMP_INSTANCES: isBooleanString(process.env?.DEL_TEMP_INSTANCES) + ? process.env.DEL_TEMP_INSTANCES === 'true' + : true, LANGUAGE: process.env?.LANGUAGE || 'en', WEBHOOK: { GLOBAL: { diff --git a/src/dev-env.yml b/src/dev-env.yml index b05176bc..47950ee2 100644 --- a/src/dev-env.yml +++ b/src/dev-env.yml @@ -47,6 +47,7 @@ LOG: # Default time: 5 minutes # If you don't even want an expiration, enter the value false DEL_INSTANCE: false # or false +DEL_TEMP_INSTANCES: true # Delete instances with status closed on start # Temporary data storage STORE: diff --git a/src/whatsapp/services/monitor.service.ts b/src/whatsapp/services/monitor.service.ts index 0b6f5863..e7eb0bc1 100644 --- a/src/whatsapp/services/monitor.service.ts +++ b/src/whatsapp/services/monitor.service.ts @@ -480,6 +480,11 @@ 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) {