import { Job } from 'bullmq'; interface SendJobData { accountId: string; tenantId: string; chatId: number; payload: Record; } // This is the BullMQ worker processor for send-message queue // In production, this runs as a separate process registered in the module export async function sendMessageProcessor(job: Job): Promise { const { accountId, payload } = job.data; // In production, this would use the TdlibClientManagerService // to send the message via TDLib. The worker would be // set up with NestJS context to inject dependencies. job.log(`Processing send for account ${accountId} to chat ${job.data.chatId}`); await job.updateProgress(50); try { // Simulated: In production, this calls tdlibClientManager.sendRequest(accountId, payload) job.log(`Message sent successfully to chat ${job.data.chatId}`); return { success: true, timestamp: new Date().toISOString(), }; } catch (err) { job.log(`Send failed: ${err}`); throw err; } } // Worker setup (used when running as a standalone process) export function setupSendMessageWorker() { const { Worker } = require('bullmq'); const redisConfig = { host: process.env.REDIS_HOST || 'localhost', port: parseInt(process.env.REDIS_PORT || '6379', 10), password: process.env.REDIS_PASSWORD || undefined, }; const worker = new Worker('send-message', sendMessageProcessor, { connection: redisConfig, concurrency: 5, limiter: { max: 30, duration: 1000, }, }); worker.on('completed', (job) => { console.log(`Send job ${job.id} completed`); }); worker.on('failed', (job, err) => { console.error(`Send job ${job?.id} failed: ${err.message}`); }); return worker; }