-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
GitHub Actions edited this page Jan 14, 2025
·
1 revision
To use the pop-queue library in your project, import it as follows:
const { PopQueue } = require('pop-queue');Create a queue by instantiating the PopQueue class with the required parameters:
const queue = new PopQueue('mongodb://localhost:27017', 'redis://localhost:6379', 'myDatabase', 'myCollection', 3);Define a job using the define method:
queue.define('myJob', async (job) => {
console.log('Processing job:', job);
// Perform job processing logic here
return true;
});Enqueue a job using the now method:
queue.now({ data: 'jobData' }, 'myJob', 'jobIdentifier', Date.now());Start the queue using the start method:
queue.start();Here is a complete example of using the pop-queue library:
const { PopQueue } = require('pop-queue');
const queue = new PopQueue('mongodb://localhost:27017', 'redis://localhost:6379', 'myDatabase', 'myCollection', 3);
queue.define('myJob', async (job) => {
console.log('Processing job:', job);
// Perform job processing logic here
return true;
});
queue.now({ data: 'jobData' }, 'myJob', 'jobIdentifier', Date.now());
queue.start();