2.0.1 • Published 2 months ago
@tonoid/bull v2.0.1
@tonoid/bull
Bull plugin for @tonoid/helpers - handling messaging queues and background tasks
Init options
redisOptions.url
: (defaults:process.env.BULL_REDIS_URL || process.env.REDIS_URL
) Redis url, if set it overrides other auth options.redisOptions.db
: (defaults:process.env.BULL_REDIS_DB || process.env.REDIS_DB || '0'
) Redis database.redisOptions.errorHandler
: (default:(err) => {}
) Handle redis connect errormiddleware
: function to manipulate{ queues, queuesObject, redisOptions }
, useful if you're using admin ui like @bull-boardqueues
: (Array) Available queuesqueues[].name
: (string - required) Queue namequeues[].consumer
: (function({ queue, queues } - optional) - required) Consumer function to progress the queue
Exported context attributes
.queues
: Object containing all queues (useful to add to a queue)
Usage example
const { context, init } = require('@tonoid/helpers');
const bull = require('@tonoid/bull');
const jsonStringifyQueue = ({ queue }) => {
queue.process(async (job) => {
// Do something with job.data
job.progress(10);
job.log('Computing data');
await new Promise((r) => setTimeout(r, 1000));
job.log('Almost there');
job.progress(90);
return JSON.stringify(job.data);
});
}
(async () => {
await init([
bull(
{
redisOptions: {
url: 'redis://locahost:6379',
db: 0,
errorHandler: (err, scope) => console.error(scope, err)
},
queues: [
{ name: 'jsonStringify', consumer: jsonStringifyConsumer },
],
},
'myBull',
),
]);
const job = await context.myBull.jsonStringify.add({ foo: 'bar' });
const result = await job.finished();
console.log(result);
})();
Credits
This module is maintained by Simo Elalj @tonoid
2.0.1
2 months ago
1.2.0
5 months ago
1.1.0
5 months ago
1.0.0
5 months ago
1.3.0
5 months ago
2.0.0
5 months ago
0.1.0
9 months ago
0.2.1
7 months ago
0.2.0
7 months ago
0.0.14
11 months ago
0.0.13
1 year ago
0.0.10
2 years ago
0.0.11
2 years ago
0.0.12
2 years ago
0.0.9
2 years ago
0.0.8
2 years ago
0.0.7
2 years ago
0.0.6
3 years ago
0.0.5
3 years ago
0.0.4
3 years ago
0.0.3
3 years ago
0.0.2
3 years ago
0.0.1
3 years ago