add worker
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { createBullBoard } from '@bull-board/api';
|
import { createBullBoard } from '@bull-board/api';
|
||||||
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
||||||
import { ExpressAdapter } from '@bull-board/express';
|
import { ExpressAdapter } from '@bull-board/express';
|
||||||
|
import type { WorkerOptions } from 'bullmq';
|
||||||
import { Worker } from 'bullmq';
|
import { Worker } from 'bullmq';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
|
||||||
@@ -10,20 +11,21 @@ import { cronQueue } from '@mixan/queue/src/queues';
|
|||||||
import { cronJob } from './jobs/cron';
|
import { cronJob } from './jobs/cron';
|
||||||
import { eventsJob } from './jobs/events';
|
import { eventsJob } from './jobs/events';
|
||||||
|
|
||||||
const PORT = process.env.PORT || 3000;
|
const PORT = parseInt(process.env.WORKER_PORT || '3000', 10);
|
||||||
const serverAdapter = new ExpressAdapter();
|
const serverAdapter = new ExpressAdapter();
|
||||||
serverAdapter.setBasePath('/');
|
serverAdapter.setBasePath('/');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
new Worker(eventsQueue.name, eventsJob, {
|
const workerOptions: WorkerOptions = {
|
||||||
connection,
|
connection,
|
||||||
});
|
concurrency: parseInt(process.env.CONCURRENCY || '1', 10),
|
||||||
|
};
|
||||||
new Worker(cronQueue.name, cronJob, {
|
|
||||||
connection,
|
|
||||||
});
|
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
|
new Worker(eventsQueue.name, eventsJob, workerOptions);
|
||||||
|
|
||||||
|
new Worker(cronQueue.name, cronJob, workerOptions);
|
||||||
|
|
||||||
createBullBoard({
|
createBullBoard({
|
||||||
queues: [new BullMQAdapter(eventsQueue), new BullMQAdapter(cronQueue)],
|
queues: [new BullMQAdapter(eventsQueue), new BullMQAdapter(cronQueue)],
|
||||||
serverAdapter: serverAdapter,
|
serverAdapter: serverAdapter,
|
||||||
@@ -53,9 +55,6 @@ async function start() {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
// if (!repeatableJobs.find((job) => job.name === 'salt')) {
|
|
||||||
// console.log('Add salt job to queue');
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start();
|
start();
|
||||||
|
|||||||
4
captain-definition-worker
Normal file
4
captain-definition-worker
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 2,
|
||||||
|
"dockerfilePath": "./apps/worker/Dockerfile"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user