Merge pull request #758 from judsonjuniorr/v2-instance-cleanup

Remove instance from redis even if using database
This commit is contained in:
Davidson Gomes 2024-08-13 15:55:45 -03:00 committed by GitHub
commit 7f83263b63
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -120,6 +120,7 @@ export class WAMonitoringService {
} }
public async cleaningUp(instanceName: string) { public async cleaningUp(instanceName: string) {
let instanceDbId: string;
if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) { if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) {
const instance = await this.prismaRepository.instance.update({ const instance = await this.prismaRepository.instance.update({
where: { name: instanceName }, where: { name: instanceName },
@ -130,13 +131,15 @@ export class WAMonitoringService {
rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true }); rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true });
instanceDbId = instance.id;
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } }); await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
return;
} }
if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) { if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) {
await this.cache.delete(instanceName); await this.cache.delete(instanceName);
return; if (instanceDbId) {
await this.cache.delete(instanceDbId);
}
} }
if (this.providerSession?.ENABLED) { if (this.providerSession?.ENABLED) {