50 lines
1.4 KiB
JavaScript
50 lines
1.4 KiB
JavaScript
const path = require('path');
|
|
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
|
require('dotenv').config({ path: path.join(__dirname, '../../backend/.env') });
|
|
|
|
const { Worker } = require('bullmq');
|
|
const { connectDB } = require('../src/config/database');
|
|
const { getRedisConnection, verifyRedisConnection, QUEUE_PREFIX, INBOUND_QUEUE } = require('../src/config/queue');
|
|
|
|
function attachWorkerErrors(worker, label) {
|
|
worker.on('error', (err) => {
|
|
console.error(`[${label}] Redis/BullMQ error:`, err.message);
|
|
if (err.code === 'ECONNRESET') {
|
|
console.error(
|
|
`[${label}] Connection reset — if using DigitalOcean Redis, ensure REDIS_URL uses rediss:// or REDIS_TLS=true`,
|
|
);
|
|
}
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
await connectDB();
|
|
await verifyRedisConnection();
|
|
|
|
const { processInboundMessage } = require('../src/services/conciergeInbound');
|
|
|
|
const worker = new Worker(
|
|
INBOUND_QUEUE,
|
|
async (job) => {
|
|
await processInboundMessage(job.data);
|
|
},
|
|
{
|
|
connection: getRedisConnection(),
|
|
prefix: QUEUE_PREFIX,
|
|
concurrency: 5,
|
|
},
|
|
);
|
|
|
|
worker.on('failed', (job, err) => {
|
|
console.error('[inbound] failed', job?.id, err.message);
|
|
});
|
|
attachWorkerErrors(worker, 'inbound');
|
|
|
|
console.log('[inbound] worker started');
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|