fix: worker
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { createBullBoard } from '@bull-board/api';
|
import { createBullBoard } from '@bull-board/api';
|
||||||
import { BullMQAdapter } from '@bull-board/api/dist/src/queueAdapters/bullMQ.js';
|
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
|
||||||
import { ExpressAdapter } from '@bull-board/express';
|
import { ExpressAdapter } from '@bull-board/express';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
|
||||||
@@ -13,8 +13,6 @@ import {
|
|||||||
} from '@openpanel/queue';
|
} from '@openpanel/queue';
|
||||||
import client from 'prom-client';
|
import client from 'prom-client';
|
||||||
|
|
||||||
import { getRedisQueue } from '@openpanel/redis';
|
|
||||||
import { Queue, Worker } from 'bullmq';
|
|
||||||
import { BullBoardGroupMQAdapter } from 'groupmq';
|
import { BullBoardGroupMQAdapter } from 'groupmq';
|
||||||
import sourceMapSupport from 'source-map-support';
|
import sourceMapSupport from 'source-map-support';
|
||||||
import { bootCron } from './boot-cron';
|
import { bootCron } from './boot-cron';
|
||||||
@@ -24,28 +22,6 @@ import { logger } from './utils/logger';
|
|||||||
|
|
||||||
sourceMapSupport.install();
|
sourceMapSupport.install();
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
const test = new Worker(
|
|
||||||
'duplicateEvents',
|
|
||||||
async (job) => {
|
|
||||||
await sleep(5000);
|
|
||||||
|
|
||||||
return 'done';
|
|
||||||
},
|
|
||||||
{
|
|
||||||
connection: getRedisQueue(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
const testQueue = new Queue('duplicateEvents', {
|
|
||||||
connection: getRedisQueue(),
|
|
||||||
defaultJobOptions: {
|
|
||||||
removeOnComplete: {
|
|
||||||
age: 10,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
async function start() {
|
async function start() {
|
||||||
const collectDefaultMetrics = client.collectDefaultMetrics;
|
const collectDefaultMetrics = client.collectDefaultMetrics;
|
||||||
collectDefaultMetrics({ register });
|
collectDefaultMetrics({ register });
|
||||||
@@ -70,33 +46,6 @@ async function start() {
|
|||||||
app.use('/', serverAdapter.getRouter());
|
app.use('/', serverAdapter.getRouter());
|
||||||
}
|
}
|
||||||
|
|
||||||
const hashPayload = (payload: Record<string, unknown>) => {
|
|
||||||
return 'event-hash-here...';
|
|
||||||
};
|
|
||||||
|
|
||||||
app.get('/test', async (req, res) => {
|
|
||||||
try {
|
|
||||||
const job = await testQueue.add(
|
|
||||||
'test',
|
|
||||||
{
|
|
||||||
message: 'Test job!',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
jobId: hashPayload(req.body),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
res.json({ jobId: job.id, opts: job.opts, status: await job.getState() });
|
|
||||||
} catch (error) {
|
|
||||||
console.log('error', error);
|
|
||||||
|
|
||||||
if (error instanceof Error) {
|
|
||||||
res.status(500).json({ error: error.message });
|
|
||||||
} else {
|
|
||||||
res.status(500).json({ error: 'Unknown error' });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/metrics', (req, res) => {
|
app.get('/metrics', (req, res) => {
|
||||||
res.set('Content-Type', register.contentType);
|
res.set('Content-Type', register.contentType);
|
||||||
register
|
register
|
||||||
|
|||||||
Reference in New Issue
Block a user