diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f55729..8dc820a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ -# 2.0.4-beta (beta) +# 2.0.4-rc (release candidate) ### Features -* New manager v2.0.0 +* New manager v2.0 ### Fixed diff --git a/src/api/controllers/instance.controller.ts b/src/api/controllers/instance.controller.ts index ecb78e40..72e64265 100644 --- a/src/api/controllers/instance.controller.ts +++ b/src/api/controllers/instance.controller.ts @@ -594,11 +594,11 @@ export class InstanceController { switch (state) { case 'open': if (this.configService.get('CHATWOOT').ENABLED) instance.clearCacheChatwoot(); - // await instance.reloadConnection(); - await instance.client?.ws?.close(); - await delay(2000); - return await this.connectionState({ instanceName }); + this.logger.info('Connection closed, restarting instance' + instanceName); + instance.client?.ws?.close(); + instance.client?.end(new Error('restart')); + return await this.connectToWhatsapp({ instanceName }); default: return await this.connectionState({ instanceName }); } @@ -690,7 +690,6 @@ export class InstanceController { this.logger.error(error); } - delete this.waMonitor.waInstances[instanceName]; this.eventEmitter.emit('remove.instance', instanceName, 'inner'); return { status: 'SUCCESS', error: false, response: { message: 'Instance deleted' } }; } catch (error) { diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index acdbc4e6..44bb77ed 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -336,18 +336,18 @@ export class WAMonitoringService { private removeInstance() { this.eventEmitter.on('remove.instance', async (instanceName: string) => { - try { - this.waInstances[instanceName] = undefined; - } catch (error) { - this.logger.error(error); - } - try { this.cleaningUp(instanceName); this.cleaningStoreData(instanceName); } finally { this.logger.warn(`Instance "${instanceName}" - REMOVED`); } + + try { + delete this.waInstances[instanceName]; + } catch (error) { + this.logger.error(error); + } }); this.eventEmitter.on('logout.instance', async (instanceName: string) => { try {