Skip to content

Commit

Permalink
refactor: use bullmq 4.6.0 promoteJobs if available
Browse files Browse the repository at this point in the history
  • Loading branch information
felixmosh committed Jul 20, 2023
1 parent 902bdb5 commit e93e1c5
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 89 deletions.
7 changes: 1 addition & 6 deletions example.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Bull from 'bull';
import Queue3 from 'bull';
import { Queue as QueueMQ, QueueScheduler, Worker } from 'bullmq';
import { Queue as QueueMQ, Worker } from 'bullmq';
import express from 'express';
import { BullMQAdapter } from '@bull-board/api/src/queueAdapters/bullMQ';
import { BullAdapter } from '@bull-board/api/src/queueAdapters/bull';
Expand Down Expand Up @@ -32,11 +32,6 @@ function setupBullProcessor(bullQueue: Bull.Queue) {
}

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

new Worker(
queueName,
async (job) => {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-express-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@bull-board/express": "^3.10.4",
"body-parser": "^1.20.0",
"bullmq": "^1.80.4",
"bullmq": "^4.6.0",
"connect-ensure-login": "^0.1.1",
"express": "^4.17.3",
"express-session": "^1.17.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@bull-board/express": "^3.10.4",
"bullmq": "^1.80.4",
"bullmq": "^4.6.0",
"express": "^4.17.3"
}
}
2 changes: 1 addition & 1 deletion examples/with-fastify-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@fastify/cookie": "^7.3.1",
"@fastify/jwt": "^6.3.2",
"@fastify/view": "^7.0.0",
"bullmq": "^1.81.1",
"bullmq": "^4.6.0",
"fastify": "^4.10.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/with-fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@bull-board/fastify": "^5.0.0",
"@bull-board/api": "^5.0.0",
"bullmq": "^3.10.1",
"bullmq": "^4.6.0",
"fastify": "^4.15.0"
}
}
2 changes: 1 addition & 1 deletion examples/with-hapi-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"@bull-board/hapi": "^5.0.0",
"@hapi/basic": "^6.0.0",
"@hapi/hapi": "^20.2.1",
"bullmq": "^3.10.3"
"bullmq": "^4.6.0"
}
}
2 changes: 1 addition & 1 deletion examples/with-hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"dependencies": {
"@bull-board/hapi": "^5.0.0",
"@hapi/hapi": "^20.2.1",
"bullmq": "^3.10.3"
"bullmq": "^4.6.0"
}
}
2 changes: 1 addition & 1 deletion examples/with-koa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@bull-board/koa": "*",
"bullmq": "^1.80.4",
"bullmq": "^4.6.0",
"koa": "^2.13.4",
"koa-router": "^10.1.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/with-multiple-instances/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@bull-board/express": "^4.2.1",
"body-parser": "^1.20.0",
"bullmq": "^1.80.4",
"bullmq": "^4.6.0",
"express": "^4.17.3"
}
}
2 changes: 1 addition & 1 deletion examples/with-nestjs-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^8.0.0",
"bullmq": "^3.15.4",
"bullmq": "^4.6.0",
"@bull-board/nestjs": "^5.3.1",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/with-nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/platform-express": "^9.0.0",
"bullmq": "^3.13.4",
"bullmq": "^4.6.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
},
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@
"@typescript-eslint/parser": "^5.60.0",
"auto-changelog": "^2.4.0",
"babel-loader": "^8.2.5",
"bull": "^4.9.0",
"bullmq": "^1.90.1",
"concurrently": "^7.4.0",
"eslint": "^7.27.0",
"eslint-config-prettier": "^8.5.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
},
"devDependencies": {
"@types/node": "^17.0.25",
"bull": "^4.10.2",
"bullmq": "^1.80.6",
"ioredis-mock": "^7.2.0"
"bull": "^4.10.4",
"bullmq": "^4.6.0",
"ioredis-mock": "^8.8.1"
},
"peerDependencies": {
"@bull-board/ui": "5.6.1"
Expand Down
20 changes: 8 additions & 12 deletions packages/api/src/handlers/promoteAll.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { BullBoardRequest, ControllerHandlerReturnType } from "../../typings/app";
import { BaseAdapter } from "../queueAdapters/base";
import { STATUSES } from "../constants/statuses";
import { queueProvider } from "../providers/queue";
import { BullBoardRequest, ControllerHandlerReturnType } from '../../typings/app';
import { queueProvider } from '../providers/queue';
import { BaseAdapter } from '../queueAdapters/base';

async function promoteAll(
_req: BullBoardRequest,
queue: BaseAdapter
): Promise<ControllerHandlerReturnType> {
const queueStatus = STATUSES.delayed;
_req: BullBoardRequest,
queue: BaseAdapter
): Promise<ControllerHandlerReturnType> {
await queue.promoteAll();

const jobs = await queue.getJobs([queueStatus]);
await Promise.all(jobs.map((job) => job.promote()));

return { status: 200, body: {} };
return { status: 200, body: {} };
}

export const promoteAllHandler = queueProvider(promoteAll);
2 changes: 2 additions & 0 deletions packages/api/src/queueAdapters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,6 @@ export abstract class BaseAdapter {
public abstract resume(): Promise<void>;

public abstract empty(): Promise<void>;

public abstract promoteAll(): Promise<void>;
}
6 changes: 6 additions & 0 deletions packages/api/src/queueAdapters/bull.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Job, Queue } from 'bull';
import { JobCleanStatus, JobCounts, JobStatus, QueueAdapterOptions } from '../../typings/app';
import { STATUSES } from '../constants/statuses';
import { BaseAdapter } from './base';

export class BullAdapter extends BaseAdapter {
Expand Down Expand Up @@ -64,4 +65,9 @@ export class BullAdapter extends BaseAdapter {
public empty(): Promise<void> {
return this.queue.empty();
}

public async promoteAll(): Promise<void> {
const jobs = await this.getJobs([STATUSES.delayed]);
await Promise.all(jobs.map((job) => job.promote()));
}
}
11 changes: 11 additions & 0 deletions packages/api/src/queueAdapters/bullMQ.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Job, Queue } from 'bullmq';
import { JobCleanStatus, JobCounts, JobStatus, QueueAdapterOptions } from '../../typings/app';
import { STATUSES } from '../constants/statuses';
import { BaseAdapter } from './base';

export class BullMQAdapter extends BaseAdapter {
Expand Down Expand Up @@ -53,4 +54,14 @@ export class BullMQAdapter extends BaseAdapter {
public empty(): Promise<void> {
return this.queue.drain();
}

public async promoteAll(): Promise<void> {
// since bullmq 4.6.0
if (typeof this.queue.promoteJobs === 'function') {
await this.queue.promoteJobs();
} else {
const jobs = await this.getJobs([STATUSES.delayed]);
await Promise.all(jobs.map((job) => job.promote()));
}
}
}
2 changes: 1 addition & 1 deletion packages/nestjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@nestjs/core": "^10.0.1",
"@types/node": "18.16.16",
"bull": "^4.10.4",
"bullmq": "^3.15.8",
"bullmq": "^4.6.0",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1",
"typescript": "^5.1.3"
Expand Down
76 changes: 21 additions & 55 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,12 @@
resolved "https://registry.yarnpkg.com/@iarna/toml/-/toml-2.2.5.tgz#b32366c89b43c6f8cefbdefac778b9c828e3ba8c"
integrity sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg==

"@ioredis/commands@^1.1.1":
"@ioredis/as-callback@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@ioredis/as-callback/-/as-callback-3.0.0.tgz#b96c9b05e6701e85ec6a5e62fa254071b0aec97f"
integrity sha512-Kqv1rZ3WbgOrS+hgzJ5xG5WQuhvzzSTRYvNeyPMLOAM78MHSnuKI20JeJGbpuAt//LCuP0vsexZcorqW7kWhJg==

"@ioredis/commands@^1.1.1", "@ioredis/commands@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"
integrity sha512-Sx1pU8EM64o2BrqNpEO1CNLtKQwyhuXuqyfH7oGKCk+1a33d2r5saW8zNwm3j6BTExtjrv2BxTgzzkMwts6vGg==
Expand Down Expand Up @@ -5402,7 +5407,7 @@ builtins@^1.0.3:
resolved "https://registry.yarnpkg.com/builtins/-/builtins-1.0.3.tgz#cb94faeb61c8696451db36534e1422f94f0aee88"
integrity sha1-y5T662HIaWRR2zZTThQi+U8K7og=

bull@^4.10.2, bull@^4.10.4, bull@^4.9.0:
bull@^4.10.4:
version "4.10.4"
resolved "https://registry.yarnpkg.com/bull/-/bull-4.10.4.tgz#db39ee0c3bfbe3b76f1f35db800501de5bba4f84"
integrity sha512-o9m/7HjS/Or3vqRd59evBlWCXd9Lp+ALppKseoSKHaykK46SmRjAilX98PgmOz1yeVaurt8D5UtvEt4bUjM3eA==
Expand All @@ -5416,32 +5421,17 @@ bull@^4.10.2, bull@^4.10.4, bull@^4.9.0:
semver "^7.3.2"
uuid "^8.3.0"

bullmq@^1.80.6, bullmq@^1.90.1:
version "1.91.1"
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-1.91.1.tgz#ed17cfd4e314afa398fd099a32d365046b1ed4bc"
integrity sha512-u7dat9I8ZwouZ651AMZkBSvB6NVUPpnAjd4iokd9DM41whqIBnDjuL11h7+kEjcpiDKj6E+wxZiER00FqirZQg==
dependencies:
cron-parser "^4.6.0"
get-port "6.1.2"
glob "^8.0.3"
ioredis "^5.2.2"
lodash "^4.17.21"
msgpackr "^1.6.2"
semver "^7.3.7"
tslib "^2.0.0"
uuid "^9.0.0"

bullmq@^3.15.8:
version "3.15.8"
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-3.15.8.tgz#e8ec5b46b0b7d7ce57e509280d03745109411e05"
integrity sha512-k3uimHGhl5svqD7SEak+iI6c5DxeLOaOXzCufI9Ic0ST3nJr69v71TGR4cXCTXdgCff3tLec5HgoBnfyWjgn5A==
bullmq@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/bullmq/-/bullmq-4.6.0.tgz#13e23ec205e1e7f75ce4c0948d14b4f5bc81a31d"
integrity sha512-RVJSC/DhruJpSoIWYS69NMZ+qTVZpWF4fZ9WKxP9QqY7WHK6Hbm+S5D7W4XN1HAExIGHTmWYZMiqKnBgxEi9XA==
dependencies:
cron-parser "^4.6.0"
glob "^8.0.3"
ioredis "^5.3.2"
lodash "^4.17.21"
msgpackr "^1.6.2"
semver "^7.3.7"
semver "^7.5.4"
tslib "^2.0.0"
uuid "^9.0.0"

Expand Down Expand Up @@ -6562,7 +6552,7 @@ delegates@^1.0.0:
resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a"
integrity sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==

denque@^2.0.1, denque@^2.1.0:
denque@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/denque/-/denque-2.1.0.tgz#e93e1a6569fb5e66f16a3c2a2964617d349d6ab1"
integrity sha512-HVQE3AAb/pxF8fQAoiqpvg9i3evqug3hoiwakOyZAwJm+6vZehbkYXZ0l4JxS+I3QxM97v5aaRNhj8v5oBhekw==
Expand Down Expand Up @@ -7885,11 +7875,6 @@ get-pkg-repo@^4.0.0:
through2 "^2.0.0"
yargs "^16.2.0"

[email protected]:
version "6.1.2"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-6.1.2.tgz#c1228abb67ba0e17fb346da33b15187833b9c08a"
integrity sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==

get-port@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
Expand Down Expand Up @@ -8692,15 +8677,16 @@ invariant@^2.2.4:
dependencies:
loose-envify "^1.0.0"

ioredis-mock@^7.2.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/ioredis-mock/-/ioredis-mock-7.4.0.tgz#953ca4ccd79eec36a78d86b5d5028f4d6098eaae"
integrity sha512-jcNG+9YjjBA1p6Hb1nYaC1yhW+n9S5VOgbGZXt59ZmtI2WrPWH+lSD4gE017uaGitPqW7tquFdAfcBPvFEQbew==
ioredis-mock@^8.8.1:
version "8.8.1"
resolved "https://registry.yarnpkg.com/ioredis-mock/-/ioredis-mock-8.8.1.tgz#46e22a93e06e4377b09b66143351a3dda552e04f"
integrity sha512-zXSaDf86EcDFVf8jMOirWU6Js4WcwLd/cxwJiCh9EbD1GoHfeE/fVqLhLz/l1MkyL85Fb6MwfF2Fr/9819Ul9Q==
dependencies:
"@ioredis/as-callback" "^3.0.0"
"@ioredis/commands" "^1.2.0"
fengari "^0.1.4"
fengari-interop "^0.1.3"
redis-commands "^1.7.0"
standard-as-callback "^2.1.0"
semver "^7.5.4"

ioredis@^5.0.0, ioredis@^5.3.2:
version "5.3.2"
Expand All @@ -8717,21 +8703,6 @@ ioredis@^5.0.0, ioredis@^5.3.2:
redis-parser "^3.0.0"
standard-as-callback "^2.1.0"

ioredis@^5.2.2:
version "5.2.4"
resolved "https://registry.yarnpkg.com/ioredis/-/ioredis-5.2.4.tgz#9e262a668bc29bae98f2054c1e0d7efd86996b96"
integrity sha512-qIpuAEt32lZJQ0XyrloCRdlEdUUNGG9i0UOk6zgzK6igyudNWqEBxfH6OlbnOOoBBvr1WB02mm8fR55CnikRng==
dependencies:
"@ioredis/commands" "^1.1.1"
cluster-key-slot "^1.1.0"
debug "^4.3.4"
denque "^2.0.1"
lodash.defaults "^4.2.0"
lodash.isarguments "^3.1.0"
redis-errors "^1.2.0"
redis-parser "^3.0.0"
standard-as-callback "^2.1.0"

ip@^1.1.5, ip@^1.1.8:
version "1.1.8"
resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.8.tgz#ae05948f6b075435ed3307acce04629da8cdbf48"
Expand Down Expand Up @@ -12766,11 +12737,6 @@ redent@^3.0.0:
indent-string "^4.0.0"
strip-indent "^3.0.0"

redis-commands@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/redis-commands/-/redis-commands-1.7.0.tgz#15a6fea2d58281e27b1cd1acfb4b293e278c3a89"
integrity sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ==

redis-errors@^1.0.0, redis-errors@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/redis-errors/-/redis-errors-1.2.0.tgz#eb62d2adb15e4eaf4610c04afe1529384250abad"
Expand Down Expand Up @@ -13291,7 +13257,7 @@ semver@^6.0.0, semver@^6.3.0, semver@^6.3.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.0, semver@^7.5.3:
semver@^7.1.1, semver@^7.1.3, semver@^7.2.1, semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7, semver@^7.3.8, semver@^7.5.0, semver@^7.5.3, semver@^7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA==
Expand Down

0 comments on commit e93e1c5

Please sign in to comment.