Skip to content

Commit

Permalink
Bump Hapi example
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Apr 5, 2023
1 parent 82a0203 commit 2df15b1
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 170 deletions.
31 changes: 15 additions & 16 deletions examples/with-hapi/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createBullBoard } = require('@bull-board/api');
const { BullMQAdapter } = require('@bull-board/api/bullMQAdapter');
const { HapiAdapter } = require('@bull-board/hapi');
const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq');
const { Queue: QueueMQ, Worker } = require('bullmq');
const Hapi = require('@hapi/hapi');

const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t * 1000));
Expand All @@ -16,22 +16,21 @@ const redisOptions = {
const createQueueMQ = (name) => new QueueMQ(name, { connection: redisOptions });

async function setupBullMQProcessor(queueName) {
const queueScheduler = new QueueScheduler(queueName, {
connection: redisOptions,
});
await queueScheduler.waitUntilReady();

new Worker(queueName, async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random());
await job.updateProgress(i);
await job.log(`Processing job at interval ${i}`);

if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`);
}
new Worker(
queueName,
async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random());
await job.updateProgress(i);
await job.log(`Processing job at interval ${i}`);

if (Math.random() * 200 < 1) throw new Error(`Random error ${i}`);
}

return { jobId: `This is the return value of job (${job.id})` };
});
return { jobId: `This is the return value of job (${job.id})` };
},
{ connection: redisOptions }
);
}

const run = async () => {
Expand Down
4 changes: 2 additions & 2 deletions examples/with-hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"author": "felixmosh",
"license": "ISC",
"dependencies": {
"@bull-board/hapi": "^3.10.4",
"@bull-board/hapi": "^5.0.0",
"@hapi/hapi": "^20.2.1",
"bullmq": "^1.80.4"
"bullmq": "^3.10.3"
}
}
Loading

0 comments on commit 2df15b1

Please sign in to comment.