Skip to content

Commit

Permalink
(WIP) Adding Job Scheduler support for BullMQ Queues
Browse files Browse the repository at this point in the history
  • Loading branch information
lpoulin committed Nov 27, 2024
1 parent c47af53 commit 0ec8c82
Show file tree
Hide file tree
Showing 81 changed files with 29,438 additions and 3,174 deletions.
32 changes: 32 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"version": "0.2.0",
"compounds": [
{
"name": "Debug",
"configurations": ["Debug API", "Debug UI"]
}
],
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug API",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/example.ts",
"runtimeExecutable": "yarn",
"runtimeArgs": ["start:dev:server"],
"outFiles": ["${workspaceFolder}/**/*.js"],
"console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Debug UI",
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "yarn",
"runtimeArgs": ["lerna", "run", "--stream", "--scope", "@bull-board/ui", "dev"],
"outFiles": ["${workspaceFolder}/packages/ui/dist/**/*.js"],
"console": "integratedTerminal"
}
]
}
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,68 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v6.5.3](https://github.com/felixmosh/bull-board/compare/v6.5.2...v6.5.3)

- fix(JobActions): show actions for "waiting children" jobs just as for "waiting" ones [`#855`](https://github.com/felixmosh/bull-board/pull/855)
- chore(deps): bump the npm_and_yarn group across 6 directories with 1 update [`#853`](https://github.com/felixmosh/bull-board/pull/853)
- bump hono version [`ca566d6`](https://github.com/felixmosh/bull-board/commit/ca566d67816de38f417b4f12b53ca760f3c7aadb)

#### [v6.5.2](https://github.com/felixmosh/bull-board/compare/v6.5.1...v6.5.2)

> 16 November 2024
- Release 6.5.2 [`bfd8b4e`](https://github.com/felixmosh/bull-board/commit/bfd8b4ed12547a506141dba92a003d7fac3ed358)
- fix: support for older BullMQ versions, round 2 [`1634438`](https://github.com/felixmosh/bull-board/commit/1634438317f1cc7c429e41540e8c7e3587df2fb2)

#### [v6.5.1](https://github.com/felixmosh/bull-board/compare/v6.5.0...v6.5.1)

> 16 November 2024
- Fix h3 adapter route param decode [`#852`](https://github.com/felixmosh/bull-board/pull/852)
- Release 6.5.1 [`c72b28c`](https://github.com/felixmosh/bull-board/commit/c72b28cd283197e827fc3e322c8d7550db02c3c9)
- fix: elysia readme [`3f92a7e`](https://github.com/felixmosh/bull-board/commit/3f92a7e092ada9b01ec4b3076dc641291a44ee2a)
- fix: add Elysia to main readme [`5cb902a`](https://github.com/felixmosh/bull-board/commit/5cb902a5a9825a94fae4f7933aceddc10daf2a1b)

#### [v6.5.0](https://github.com/felixmosh/bull-board/compare/v6.4.1...v6.5.0)

> 13 November 2024
- Add elysia adapter (with fixes) [`#851`](https://github.com/felixmosh/bull-board/pull/851)
- Release 6.5.0 [`5ce3088`](https://github.com/felixmosh/bull-board/commit/5ce3088c11be9f7f19c23c9be0d38c521d509876)
- elysia style fix [`5408c73`](https://github.com/felixmosh/bull-board/commit/5408c73dd72433cbd1cad0e9a5fe645df5a0aad3)
- fix: handle unsupported locale without errors [`64ee653`](https://github.com/felixmosh/bull-board/commit/64ee65347d20db424c34890ace49a589eaf02a31)

#### [v6.4.1](https://github.com/felixmosh/bull-board/compare/v6.4.0...v6.4.1)

> 13 November 2024
- Add elysia adapter [`#769`](https://github.com/felixmosh/bull-board/pull/769)
- chore(deps): bump webpack in the npm_and_yarn group across 1 directory [`#848`](https://github.com/felixmosh/bull-board/pull/848)
- fix: allow usage of bullmq-pro, closes #849 [`#849`](https://github.com/felixmosh/bull-board/issues/849)
- Deps bump [`b00834d`](https://github.com/felixmosh/bull-board/commit/b00834d453257975b65312101f9b6bbe51155637)
- Revert "Add elysia adapter (#769)" [`4b175fa`](https://github.com/felixmosh/bull-board/commit/4b175fae5ce5ce8485e74cacc88d0428e681b7d0)
- feat: remove babel.config & webpack [`0677784`](https://github.com/felixmosh/bull-board/commit/06777841932d253d3adf8b669be3b4f393f9a1cc)

#### [v6.4.0](https://github.com/felixmosh/bull-board/compare/v6.3.3...v6.4.0)

> 12 November 2024
- feat: paused jobs: support edit/duplicate/clean [`#846`](https://github.com/felixmosh/bull-board/pull/846)
- Release 6.4.0 [`b423427`](https://github.com/felixmosh/bull-board/commit/b423427621590e921bd1dd44452e4f4c0123f968)

#### [v6.3.3](https://github.com/felixmosh/bull-board/compare/v6.3.2...v6.3.3)

> 31 October 2024
- Release 6.3.3 [`38c79ee`](https://github.com/felixmosh/bull-board/commit/38c79ee63c0bd676cc42fcd067611420809916c4)
- fix: handle an error when highlighting an unmount component, occurs when navigating between tabs [`9add4ed`](https://github.com/felixmosh/bull-board/commit/9add4ed37d822c8e5bbf0973d553c2f4ed503910)
- fix: failed status should show Error tab at start [`7cad06e`](https://github.com/felixmosh/bull-board/commit/7cad06e73a2a79c8c19206c79810eb623e47ca82)

#### [v6.3.2](https://github.com/felixmosh/bull-board/compare/v6.3.1...v6.3.2)

> 29 October 2024
- Release 6.3.2 [`c47af53`](https://github.com/felixmosh/bull-board/commit/c47af5345ae2099e37c0dfea2665f20c364cf699)
- fix: add check in each one of bull queue adapters [`d0e42c7`](https://github.com/felixmosh/bull-board/commit/d0e42c7bf689400a4768e806ed1c774bafe77cab)

#### [v6.3.1](https://github.com/felixmosh/bull-board/compare/v6.3.0...v6.3.1)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ With this library you get a beautiful UI for visualizing what's happening with e
| [@bull-board/nestjs](https://www.npmjs.com/package/@bull-board/nestjs) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/nestjs) |
| [@bull-board/hono](https://www.npmjs.com/package/@bull-board/hono) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/hono) |
| [@bull-board/h3](https://www.npmjs.com/package/@bull-board/h3) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/h3) |
| [@bull-board/elysia](https://www.npmjs.com/package/@bull-board/elysia) | ![npm (scoped)](https://img.shields.io/npm/v/@bull-board/elysia) |

## Notes

Expand Down Expand Up @@ -59,6 +60,8 @@ yarn add @bull-board/nestjs
yarn add @bull-board/hono
# or
yarn add @bull-board/h3
# or
yarn add @bull-board/elysia
```

### NestJS specific setup
Expand Down Expand Up @@ -115,6 +118,7 @@ For more advanced usages check the `examples` folder, currently it contains:
7. [With Nest.js server using the express adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-nestjs) (Thanx to @lodi-g)
8. [With Hono server](https://github.com/felixmosh/bull-board/tree/master/examples/with-hono) (Thanks to @nihalgonsalves)
8. [With H3 server using the h3 adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-h3) (Thanx to @genu)
9. [With Elysia server using the elysia adapter](https://github.com/felixmosh/bull-board/tree/master/examples/with-elysia) (Thanx to @kravetsone)


### Board options
Expand Down
11 changes: 11 additions & 0 deletions docker-compose.redis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
redis:
image: redis:latest
hostname: redis
restart: unless-stopped
ports:
- 6379:6379
volumes:
- redis_data:/data
volumes:
redis_data:
16 changes: 16 additions & 0 deletions example.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import * as Bull from 'bull';
import Queue3 from 'bull';
import { Queue as QueueMQ, Worker, FlowProducer } from 'bullmq';
Expand Down Expand Up @@ -131,6 +132,19 @@ const run = async () => {
});
});

app.use('/add-scheduler', (req, res) => {
const title = req.query?.title?.toString() || 'ExampleJobScheduler';

exampleBullMq.upsertJobScheduler(title, {
// every 30 seconds
pattern: '*/30 * * * * *',
});

res.json({
ok: true,
});
});

const serverAdapter: any = new ExpressAdapter();
serverAdapter.setBasePath('/ui');

Expand All @@ -149,6 +163,8 @@ const run = async () => {
console.log(' curl http://localhost:3000/add?title=Example');
console.log('To populate the queue with custom options (opts), run:');
console.log(' curl http://localhost:3000/add?title=Test&opts[delay]=10');
console.log('To populate the queue with a job scheduler, run:');
console.log(' curl http://localhost:3000/add-scheduler?title=ExampleJobScheduler');
});
};

Expand Down
66 changes: 66 additions & 0 deletions examples/with-elysia/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { createBullBoard } from '@bull-board/api';
import { BullMQAdapter } from '@bull-board/api/bullMQAdapter';
import { ElysiaAdapter } from '../../node_modules/@bull-board/elysia';
import { Queue as QueueMQ, Worker } from 'bullmq';
import Elysia from 'elysia';

const sleep = (t: number) => new Promise((resolve) => setTimeout(resolve, t * 1000));

const redisOptions = {
port: 6379,
host: 'localhost',
password: '',
};

const createQueueMQ = (name: string) => new QueueMQ(name, { connection: redisOptions });

function setupBullMQProcessor(queueName: string) {
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 exampleBullMq = createQueueMQ('BullMQ');

setupBullMQProcessor(exampleBullMq.name);

const serverAdapter = new ElysiaAdapter('/ui');

createBullBoard({
queues: [new BullMQAdapter(exampleBullMq)],
serverAdapter,
});

const app = new Elysia()
.onError(({ error, code, request }) => {
console.error(error, code, request.method, request.url);
if (code === 'NOT_FOUND') return 'NOT_FOUND';
})
.use(serverAdapter.registerPlugin())
.get('/add', async ({ query }) => {
await exampleBullMq.add('Add', { title: query.title });

return { ok: true };
});

app.listen(3000, ({ port, url }) => {
/* eslint-disable no-console */
console.log(`Running on ${url.hostname}:${port}...`);
console.log(`For the UI of instance1, open http://localhost:${port}/ui`);
console.log('Make sure Redis is running on port 6379 by default');
console.log('To populate the queue, run:');
console.log(` curl http://localhost:${port}/add?title=Example`);
/* eslint-enable no-console */
});
18 changes: 18 additions & 0 deletions examples/with-elysia/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "bull-board-with-elysia",
"type": "module",
"version": "1.0.0",
"description": "Example of how to use Elysia server with bull-board",
"module": "index.ts",
"scripts": {
"dev": "bun --watch index.ts",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "kravetsone",
"license": "ISC",
"dependencies": {
"@bull-board/elysia": "^5.20.1",
"bullmq": "^5.13.2",
"elysia": "^1.1.24"
}
}
16 changes: 16 additions & 0 deletions examples/with-elysia/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"module": "ESNext",
"target": "ESNext",
"moduleResolution": "Bundler",
"esModuleInterop": true,
"strict": true,
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"noUncheckedIndexedAccess": true,
"verbatimModuleSyntax": true,
"rootDir": "./src",
"noEmit": true
}
}
Loading

0 comments on commit 0ec8c82

Please sign in to comment.