import { Worker } from 'bullmq';
import { redisConfig } from './config.js';
import { NotificationService } from '../../services/NotificationService.js';

export const notificationWorker = new Worker('notificationQueue', async (job) => {
    console.log(`[Worker] Processing job ${job.id} of type ${job.name}`);
    
    if (job.name === 'sendNotification') {
        await NotificationService.processJob(job.data);
    }
}, {
    connection: redisConfig,
    concurrency: 5
});

notificationWorker.on('completed', (job) => {
    console.log(`[Worker] Job ${job.id} completed successfully`);
});

notificationWorker.on('failed', (job, err) => {
    console.error(`[Worker] Job ${job?.id} failed with error: ${err.message}`);
});
