This module provides a useful helper to use the official bull-arena library.
See official documentation here.
Compatibility
The minimum supported version of Node.js is v8.
How to use it
To use the library you just need to follow the following steps.
Install the library with npm:
npm install @condor-labs/bull-arena
Import the library:
const bull = require('@condor-labs/bull-arena')(settings);
settings
object properties
Object | Property | Datatype | Default | Description |
---|
redis | port | Number | 6379 | The port number to connect to. |
redis | host | String | 127.0.0.1 | The hostname of the database you are connecting to. |
redis | password | String | | The password of that Redis user. |
options | removeOnComplete, removeOnFail, attempts, etc | | | You can check all the spoible options in the official documentation |
Examples
constants.js
module.exports = {
settings: {
redis : {
port: 6379,
host: "127.0.0.1",
password: "1"
},
options : {
removeOnComplete: 100,
removeOnFail: 100000,
attempts: 3
}
}
};
index.js
const {
settings
} = require('./constants');
try {
const bull = require('@condor-labs/bull-arena')(settings);
let queueName = 'queue-001';
const messages = [
{ "data": {
"id": 1604701460473,
"entityId": "5fa95d342390fabc79815f4b",
"data": {
"header_id": "5fa95d342390fabc79815f4b",
"sort_by": ["license.professionCode"]
}
}
},
{ "data": {
"id": 1473604701460,
"entityId": "c79815f4b5fa95d342390fab",
"data": {
"header_id": "15f4b5fa95d342390fabc798",
"sort_by": ["license.licenseCode"]
}
}
}
];
await bull.getQueue(queueName);
await bull.pushBulk(queueName, messages);
await bull.pause(queueName);
let isPausedQueue = await bull.isPaused(queueName);
console.log("is paused de queue : ",isPausedQueue);
setTimeout(async function () {
console.log("resume the queue after 10 seconds");
await bull.resume(queueName);
}, 10 * 1000);
await bull.add(queueName, `new-job-for-${queueName}`,messages[0], null);
let job = async function(job){
console.info(`running job! queue ${job.queue.name}, with id ${job.id} and name ${job.name}`);
console.log("data sent at job", job.data);
return true;
};
await bull.process(queueName,'*',job);
} catch (error) {
console.error(error)
}
Conclusion
A Bull-Arena Queue has the concept of FIRST-IN-FIRST-OUT which can map orders that are carried out simultaneously (asynchronously) to be ordered and take turns one by one (synchronous).
How to Publish
Increasing package version
You will need to update the package.json
file placed in the root folder.
identify the property version
and increase the right number in plus one.
Login in NPM by console.
npm login
[Enter username]
[Enter password]
[Enter email]
If all is ok the console will show you something like this : Logged in as USERNAME on https://registry.npmjs.org/.
Uploading a new version
npm publish --access public
Ref: https://docs.npmjs.com/getting-started/publishing-npm-packages
Note: you will need to have a NPM account, if you don't have one create one here: https://www.npmjs.com/signup
Contributors
The original author and current lead maintainer of this module is the @condor-labs development team.
More about Condorlabs Here.
License
MIT