Skip to content

Commit

Permalink
fix: remove old usage of QueueScheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Dec 18, 2023
1 parent 262ad47 commit b631a3c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
7 changes: 1 addition & 6 deletions examples/with-express-auth/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 { ExpressAdapter } = require('@bull-board/express');
const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq');
const { Queue: QueueMQ, Worker } = require('bullmq');
const session = require('express-session');
const bodyParser = require('body-parser');
const passport = require('passport');
Expand Down Expand Up @@ -51,11 +51,6 @@ 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());
Expand Down
33 changes: 16 additions & 17 deletions examples/with-koa/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 { KoaAdapter } = require('@bull-board/koa');
const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq');
const { Queue: QueueMQ, Worker } = require('bullmq');
const Koa = require('koa');
const Router = require('koa-router');

Expand All @@ -17,22 +17,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}`);
}

return { jobId: `This is the return value of job (${job.id})` };
}, { connection: redisOptions });
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})` };
},
{ connection: redisOptions }
);
}

const run = async () => {
Expand Down
15 changes: 3 additions & 12 deletions examples/with-multiple-instances/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 { ExpressAdapter } = require('@bull-board/express');
const { Queue: QueueMQ, Worker, QueueScheduler } = require('bullmq');
const { Queue: QueueMQ, Worker } = require('bullmq');
const express = require('express');

const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t * 1000));
Expand All @@ -16,11 +16,6 @@ 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());
Expand Down Expand Up @@ -82,12 +77,8 @@ const run = async () => {

app.listen(3000, () => {
console.log('Running on 3000...');
console.log(
'For the UI of instance1, open http://localhost:3000/instance1'
);
console.log(
'For the UI of instance2, open http://localhost:3000/instance2'
);
console.log('For the UI of instance1, open http://localhost:3000/instance1');
console.log('For the UI of instance2, open http://localhost:3000/instance2');
console.log('Make sure Redis is running on port 6379 by default');
console.log('To populate the queue, run:');
console.log(' curl http://localhost:3000/add?title=Example');
Expand Down

0 comments on commit b631a3c

Please sign in to comment.