From 5239e431c2e2390345213de90520981e125e53ad Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Wed, 12 Jun 2024 19:48:56 -0300 Subject: [PATCH] feat: update server and monitor services Updated server.module.ts and monitor.service.ts to improve service initialization and monitoring logic. Modified main.ts to integrate changes. This enhances the application's performance and reliability. --- src/api/server.module.ts | 9 +++++++-- src/api/services/monitor.service.ts | 2 +- src/main.ts | 12 ++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/api/server.module.ts b/src/api/server.module.ts index 9b469ea76..01560cb0a 100644 --- a/src/api/server.module.ts +++ b/src/api/server.module.ts @@ -1,5 +1,5 @@ import { CacheEngine } from '../cache/cacheengine'; -import { configService } from '../config/env.config'; +import { configService, ProviderSession } from '../config/env.config'; import { eventEmitter } from '../config/event.config'; import { Logger } from '../config/logger.config'; import { dbserver } from '../libs/db.connect'; @@ -110,7 +110,12 @@ export const repository = new RepositoryBroker( export const cache = new CacheService(new CacheEngine(configService, 'instance').getEngine()); const chatwootCache = new CacheService(new CacheEngine(configService, ChatwootService.name).getEngine()); const baileysCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine()); -const providerFiles = new ProviderFiles(configService); + +let providerFiles: ProviderFiles = null; + +if (configService.get('PROVIDER')?.ENABLED) { + providerFiles = new ProviderFiles(configService); +} export const waMonitor = new WAMonitoringService( eventEmitter, diff --git a/src/api/services/monitor.service.ts b/src/api/services/monitor.service.ts index 101b005eb..9b7809d9e 100644 --- a/src/api/services/monitor.service.ts +++ b/src/api/services/monitor.service.ts @@ -323,7 +323,7 @@ export class WAMonitoringService { this.logger.verbose('Loading instances'); try { - if (this.providerSession.ENABLED) { + if (this.providerSession?.ENABLED) { await this.loadInstancesFromProvider(); } else if (this.redis.REDIS.ENABLED && this.redis.REDIS.SAVE_INSTANCES) { await this.loadInstancesFromRedis(); diff --git a/src/main.ts b/src/main.ts index 2cc9e2806..366509e50 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,7 @@ import { initIO } from './api/integrations/websocket/libs/socket.server'; import { ProviderFiles } from './api/provider/sessions'; import { HttpStatus, router } from './api/routes/index.router'; import { waMonitor } from './api/server.module'; -import { Auth, configService, Cors, HttpServer, Rabbitmq, Sqs, Webhook } from './config/env.config'; +import { Auth, configService, Cors, HttpServer, ProviderSession, Rabbitmq, Sqs, Webhook } from './config/env.config'; import { onUnexpectedError } from './config/error.config'; import { Logger } from './config/logger.config'; import { ROOT_DIR } from './config/path.config'; @@ -27,9 +27,13 @@ async function bootstrap() { const logger = new Logger('SERVER'); const app = express(); - const providerFiles = new ProviderFiles(configService); - await providerFiles.onModuleInit(); - logger.info('Provider:Files - ON'); + let providerFiles: ProviderFiles = null; + + if (configService.get('PROVIDER')?.ENABLED) { + providerFiles = new ProviderFiles(configService); + await providerFiles.onModuleInit(); + logger.info('Provider:Files - ON'); + } app.use( cors({