26 lines
753 B
TypeScript
26 lines
753 B
TypeScript
import 'dotenv/config';
|
|
import { Worker } from 'bullmq';
|
|
import redisConnection from '../lib/queue/redis';
|
|
import { syncPolicies } from './jobs/syncPolicies';
|
|
import attachWorkerEvents from './events';
|
|
import logger from './logging';
|
|
|
|
const worker = new Worker(
|
|
'intune-sync-queue',
|
|
async (job) => {
|
|
logger.info({ event: 'job_start', jobId: job.id, name: job.name, data: job.data, timestamp: new Date().toISOString() });
|
|
return syncPolicies(job);
|
|
},
|
|
{ connection: (redisConnection as any), concurrency: 1 }
|
|
);
|
|
|
|
attachWorkerEvents(worker);
|
|
|
|
process.on('SIGINT', async () => {
|
|
logger.info('Shutting down worker...');
|
|
await worker.close();
|
|
process.exit(0);
|
|
});
|
|
|
|
logger.info('Worker started: listening for jobs on intune-sync-queue');
|