feat: Implement process worker with bullmq

This commit is contained in:
Faruk AYDIN
2022-03-05 00:15:46 +03:00
committed by Ömer Faruk Aydın
parent b288dc8c35
commit 20e725b590
9 changed files with 194 additions and 3 deletions

View File

@@ -0,0 +1,31 @@
import { Worker } from 'bullmq';
import Processor from '../services/processor';
import redisConfig from '../config/redis';
import Step from '../models/step';
import logger from '../helpers/logger';
const worker = new Worker(
'processor',
async (job) => {
const step = await Step.query()
.withGraphFetched('connection')
.findOne({
'steps.id': job.data.stepId,
})
.throwIfNotFound();
const flow = await step.$relatedQuery('flow');
const data = await new Processor(flow, step).run();
return data;
},
{ connection: redisConfig }
);
worker.on('completed', (job) => {
logger.info(`${job.id} has completed!`);
});
worker.on('failed', (job, err) => {
logger.info(`${job.id} has failed with ${err.message}`);
});