Skip to content

Commit

Permalink
Merge pull request #28 from sestolk/add-setter-functions
Browse files Browse the repository at this point in the history
Add "add and setter" functions
  • Loading branch information
vcapretz authored Oct 14, 2019
2 parents 826fbad + d02aadc commit f8fc76d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,31 @@ Or
npm i bull-board
```

## Hello world
## Hello World

### Add existing Bull Queue(s)

When you already defined your queue(s) you can add them using the addQueue function.

```js
const Queue = require('bull');

const someQueue = new Queue();
const someOtherQueue = new Queue();

const { setQueues } = require('bull-board')

setQueues(someQueue)

// OR

setQueues([
someQueue,
someOtherQueue
])
```

### Configure Queue(s) using bull-board

Remember that it depends on Redis as well, so the first step is to configure all of your queues:

Expand Down
6 changes: 5 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { createQueues, UI } = require('./')
const { createQueues, setQueues, UI } = require('./')
const app = require('express')()

const sleep = t => new Promise(resolve => setTimeout(resolve, t * 1000))
Expand All @@ -13,6 +13,10 @@ const redisOptions = {
}

const run = () => {
setQueues([/* Already defined (bull) queues */]);
// Or a single bull queue
setQueues(/* Already defined bull queue */);

const queues = createQueues(redisOptions)

const example = queues.add('example')
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ function UI() {

module.exports = {
UI: UI(),
setQueues: (bullQueues) => {
if (!Array.isArray(bullQueues)) {
bullQueues = [bullQueues];
}

bullQueues.forEach((item) => {
queues[item.name] = item;
})

return queues
},
createQueues: redis => {
return {
add: (name, opts) => {
Expand Down

0 comments on commit f8fc76d

Please sign in to comment.