Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2 #261

Merged
merged 6 commits into from
Apr 27, 2021
Merged

V2 #261

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 38 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,55 +45,60 @@ npm i bull-board

## Hello World

The first step is to let bull-board know the queues you have already set up, to do so we use the `setQueues` method.
The first step is to setup `bull-board` by calling `createBullBoard` method.

```js
const express = require('express')
const Queue = require('bull')
const QueueMQ = require('bullmq')
const { setQueues, BullMQAdapter, BullAdapter } = require('bull-board')
const { createBullBoard } = require('bull-board')
const { BullAdapter } = require('bull-board/bullAdapter')
const { bullMQAdapter } = require('bull-board/bullMQAdapter')

const someQueue = new Queue()
const someOtherQueue = new Queue()
const queueMQ = new QueueMQ()
const someQueue = new Queue('someQueueName')
const someOtherQueue = new Queue('someOtherQueueName')
const queueMQ = new QueueMQ('queueMQName')

setQueues([
const { router, setQueues, replaceQueues } = createBullBoard([
new BullAdapter(someQueue),
new BullAdapter(someOtherQueue),
new BullMQAdapter(queueMQ),
]);
```
])

You can then add `UI` to your middlewares (this can be set up using an admin endpoint with some authentication method):

```js
const app = require('express')()
const { router } = require('bull-board')
const app = express()

app.use('/admin/queues', router)

// other configurations for your server
// other configurations of your server
```

That's it! Now you can access the `/admin/queues` route and you will be able to monitor everything that is happening in your queues 😁
That's it! Now you can access the `/admin/queues` route, and you will be able to monitor everything that is happening in your queues 😁


For more advanced usages check the `examples` folder, currently it contains:
1. [Basic authentication example](https://github.com/felixmosh/bull-board/tree/master/examples/with-auth)
2. [Multiple instance of the board](https://github.com/felixmosh/bull-board/tree/master/examples/with-multiple-instances)
### Queue options
1. `readOnlyMode` (default: `false`)
Makes the UI as read only, hides all queue & job related actions
```js
const Queue = require('bull')
const QueueMQ = require('bullmq')
const { setQueues, BullMQAdapter, BullAdapter } = require('bull-board')

const someQueue = new Queue()
const someOtherQueue = new Queue()
const queueMQ = new QueueMQ()

setQueues([
new BullAdapter(someQueue, { readOnlyMode: true }), // only this queue will be in read only mode
new BullAdapter(someOtherQueue),
new BullMQAdapter(queueMQ, { readOnlyMode: true }),
]);
```

```js
const Queue = require('bull')
const QueueMQ = require('bullmq')
const { setQueues } = require('bull-board')
const { BullMQAdapter } = require('bull-board/bullMQAdapter')
const { BullAdapter } = require('bull-board/bullAdapter')

const someQueue = new Queue()
const someOtherQueue = new Queue()
const queueMQ = new QueueMQ()

const { router, setQueues, replaceQueues } = createBullBoard([
new BullAdapter(someQueue, { readOnlyMode: true }), // only this queue will be in read only mode
new BullAdapter(someOtherQueue),
new BullMQAdapter(queueMQ, { readOnlyMode: true }),
])
```

### Hosting router on a sub path

Expand All @@ -119,11 +124,11 @@ You will then find the bull-board UI at the following address `https://<server_n

## Contributing

First of all, thank you for being interested in helping out, your time is always appreciated in every way. 💯
First, thank you for being interested in helping out, your time is always appreciated in every way. 💯

Remember to read the [Code of Conduct](https://github.com/vcapretz/bull-board/blob/master/CODE_OF_CONDUCT.md) so you also help maintaining a good Open source community around this project!

Here's some tips:
Here are some tips:

- Check the [issues page](https://github.com/vcapretz/bull-board/issues) for already opened issues (or maybe even closed ones) that might already address your question/bug/feature request.
- When opening a bug report provide as much information as you can, some things might be useful for helping debugging and understading the problem
Expand All @@ -135,7 +140,7 @@ Here's some tips:

## Developing

If you want to help us solving the issues, be it a bug, a feature or a question, you might need to fork and clone this project.
If you want to help us to solve the issues, be it a bug, a feature or a question, you might need to fork and clone this project.

To fork a project means you're going to have your own version of it under your own GitHub profile, you do it by clicking the "Fork" button on the top of any project's page on GitHub.

Expand Down
1 change: 1 addition & 0 deletions bullAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BullAdapter } from './dist/queueAdapters/bull'
1 change: 1 addition & 0 deletions bullAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./dist/queueAdapters/bull')
1 change: 1 addition & 0 deletions bullMQAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { BullMQAdapter } from './dist/queueAdapters/bullMQ'
2 changes: 2 additions & 0 deletions bullMQAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference path="./dist/queueAdapters/bullMQ.d.ts" />
module.exports = require('./dist/queueAdapters/bullMQ')
48 changes: 30 additions & 18 deletions example.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import * as Bull from 'bull'
import Queue3 from 'bull'
import { Queue as QueueMQ, QueueScheduler, Worker } from 'bullmq'
import express from 'express'
import { BullMQAdapter, BullAdapter, router, setQueues } from './src'

const app = express()

const sleep = (t: number) =>
new Promise((resolve) => setTimeout(resolve, t * 1000))
import { createBullBoard } from './src'
import { BullAdapter } from './src/queueAdapters/bull'
import { BullMQAdapter } from './src/queueAdapters/bullMQ'

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

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

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

const run = async () => {
const exampleBullName = 'ExampleBull'
const exampleBull = createQueue3(exampleBullName)
const exampleBullMqName = 'ExampleBullMQ'
const exampleBullMq = createQueueMQ(exampleBullMqName)

setQueues([new BullMQAdapter(exampleBullMq), new BullAdapter(exampleBull)])

exampleBull.process(async (job) => {
function setupBullProcessor(bullQueue: Bull.Queue) {
bullQueue.process(async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random())
await job.progress(i)
Expand All @@ -36,13 +30,15 @@ const run = async () => {

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

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

new Worker(exampleBullMqName, async (job) => {
new Worker(queueName, async (job) => {
for (let i = 0; i <= 100; i++) {
await sleep(Math.random())
await job.updateProgress(i)
Expand All @@ -53,6 +49,16 @@ const run = async () => {

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

const run = async () => {
const app = express()

const exampleBull = createQueue3('ExampleBull')
const exampleBullMq = createQueueMQ('ExampleBullMQ')

await setupBullProcessor(exampleBull) // needed only for example proposes
await setupBullMQProcessor(exampleBullMq.name) // needed only for example proposes

app.use('/add', (req, res) => {
const opts = req.query.opts || ({} as any)
Expand All @@ -69,7 +75,13 @@ const run = async () => {
})
})

app.use('/ui', router)
const { router: bullBoardRouter } = createBullBoard([
new BullMQAdapter(exampleBullMq),
new BullAdapter(exampleBull),
])

app.use('/ui', bullBoardRouter)

app.listen(3000, () => {
console.log('Running on 3000...')
console.log('For the UI, open http://localhost:3000/ui')
Expand Down
Loading