UNPKG

whatsapp-crm-common

Version:

Componentes compartidos para servicios de WhatsApp CRM - Common utilities and types for WhatsApp CRM system

146 lines 4.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.globalQueueConfig = exports.queueConfigs = void 0; exports.getQueueConfig = getQueueConfig; exports.getAllQueueConfigs = getAllQueueConfigs; const event_types_1 = require("../events/types/event-types"); /** * Configuraciones para todas las colas del sistema */ exports.queueConfigs = { [event_types_1.QueueName.REALTIME]: { name: event_types_1.QueueName.REALTIME, defaultJobOptions: { attempts: 3, backoff: { type: "exponential", delay: 2000, }, ttl: 60000 * 5, // 5 minutos priority: event_types_1.EventPriority.HIGH, }, workerOptions: { concurrency: 10, // Procesar hasta 10 eventos simultáneamente limiter: { max: 100, // Máximo 100 jobs por segundo duration: 1000, }, settings: { stalledInterval: 30000, // 30 segundos maxStalledCount: 3, }, }, }, [event_types_1.QueueName.BULK]: { name: event_types_1.QueueName.BULK, defaultJobOptions: { attempts: 5, backoff: { type: "exponential", delay: 5000, }, ttl: 60000 * 30, // 30 minutos priority: event_types_1.EventPriority.BULK, }, workerOptions: { concurrency: 2, // Procesos más pesados, menos concurrencia limiter: { max: 5, // Máximo 5 jobs por segundo para evitar sobrecarga duration: 1000, }, settings: { stalledInterval: 60000, // 1 minuto maxStalledCount: 2, }, }, }, [event_types_1.QueueName.WEBHOOK]: { name: event_types_1.QueueName.WEBHOOK, defaultJobOptions: { attempts: 5, backoff: { type: "exponential", delay: 3000, }, ttl: 60000 * 10, // 10 minutos priority: event_types_1.EventPriority.MEDIUM, }, workerOptions: { concurrency: 5, limiter: { max: 20, // Limitar requests HTTP externos duration: 1000, }, settings: { stalledInterval: 45000, maxStalledCount: 3, }, }, }, [event_types_1.QueueName.NOTIFICATIONS]: { name: event_types_1.QueueName.NOTIFICATIONS, defaultJobOptions: { attempts: 3, backoff: { type: "fixed", delay: 1000, }, ttl: 60000 * 2, // 2 minutos priority: event_types_1.EventPriority.LOW, }, workerOptions: { concurrency: 8, limiter: { max: 50, duration: 1000, }, settings: { stalledInterval: 20000, maxStalledCount: 2, }, }, }, }; /** * Configuración global de colas */ exports.globalQueueConfig = { /** Configuración de conexión Redis */ connection: { /** Prefijo para las keys de las colas */ prefix: "bull", }, /** Configuraciones de limpieza automática */ cleanup: { /** Limpiar jobs completados después de X ms */ removeOnComplete: 100, /** Limpiar jobs fallidos después de X ms */ removeOnFail: 50, /** Intervalo de limpieza en ms */ cleanupInterval: 60000 * 5, // 5 minutos }, /** Configuraciones de monitoreo */ monitoring: { /** Habilitar métricas */ enableMetrics: true, /** Intervalo de reporte de métricas */ metricsInterval: 30000, // 30 segundos }, }; /** * Obtiene la configuración para una cola específica */ function getQueueConfig(queueName) { const config = exports.queueConfigs[queueName]; if (!config) { throw new Error(`Queue configuration not found for: ${queueName}`); } return config; } /** * Obtiene todas las configuraciones de colas */ function getAllQueueConfigs() { return exports.queueConfigs; } //# sourceMappingURL=queue-config.js.map