Implemented an option to toggle temp instances deletion

This commit is contained in:
Judson Cairo 2024-03-07 19:26:43 -03:00
parent 499bd4328a
commit a6adbd61db
6 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: {

View File

@ -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:

View File

@ -480,6 +480,11 @@ export class WAMonitoringService {
}
private async deleteTempInstances(collections: Collection<Document>[]) {
const shouldDelete = this.configService.get<boolean>('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) {