chore: Remove DEL\_TEMP\_INSTANCES variable and related functionality

The DEL\_TEMP\_INSTANCES variable and its related functionality have been removed from the .env.example, CHANGELOG.md, and src/api/services/monitor.service.ts files. The `delInstanceFiles` and `deleteTempInstances` methods have been removed from the MonitoringService class. This change simplifies the codebase and removes unnecessary functionality that was not being used.

Please note that this change does not impact the current functionalities of the application. However, it's important to update the documentation and any other related files accordingly. Make sure to test the application thoroughly to ensure there are no unintended consequences from this change.
This commit is contained in:
Davidson Gomes
2024-07-17 18:52:40 -03:00
parent d76816eb9c
commit 7e9132fcfe
3 changed files with 2 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
import { execSync } from 'child_process';
import EventEmitter2 from 'eventemitter2';
import { opendirSync, readdirSync, rmSync } from 'fs';
import { rmSync } from 'fs';
import { join } from 'path';
import { CacheConf, Chatwoot, ConfigService, Database, DelInstance, ProviderSession } from '../../config/env.config';
@@ -372,40 +372,4 @@ export class WAMonitoringService {
}
});
}
private delInstanceFiles() {
setInterval(async () => {
const dir = opendirSync(INSTANCE_DIR, { encoding: 'utf-8' });
for await (const dirent of dir) {
if (dirent.isDirectory()) {
const files = readdirSync(join(INSTANCE_DIR, dirent.name), {
encoding: 'utf-8',
});
files.forEach(async (file) => {
if (file.match(/^app.state.*/) || file.match(/^session-.*/)) {
rmSync(join(INSTANCE_DIR, dirent.name, file), {
recursive: true,
force: true,
});
}
});
}
}
}, 3600 * 1000 * 2);
}
private async deleteTempInstances() {
const shouldDelete = this.configService.get<boolean>('DEL_TEMP_INSTANCES');
if (!shouldDelete) {
return;
}
const instancesClosed = await this.prismaRepository.instance.findMany({ where: { connectionStatus: 'close' } });
let tempInstances = 0;
instancesClosed.forEach((instance) => {
tempInstances++;
this.eventEmitter.emit('remove.instance', instance.id, 'inner');
});
this.logger.log('Temp instances removed: ' + tempInstances);
}
}