Setting up Kue and Using it

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 379:- Setting up Kue and Using it

Kue is a priority job queue library for Node.js that allows you to handle job processing in the background. It provides features like delaying, repeating, and prioritizing tasks. In this section, we will learn how to install and set up Kue for delayed job processing in our Node.js application.

To install Kue, we can use the npm package manager. Open the terminal and type the following command:

Copy code

npm install kue

After installing Kue, we need to require it in our code and create a Kue job queue object.

javascriptCopy code

const kue = require('kue'); // create a Kue job queue object const queue = kue.createQueue();

Next, we need to define a job to be processed by Kue. The job consists of a name, data, and a processing function. We define the job and the processing function as follows:

javascriptCopy code

// define a job with a name and data const job = queue.create('email', {  subject: 'Welcome to our application',  to: '[email protected]',  template: 'welcome-email' }); // define a processing function for the job job.on('complete', function () {  console.log('Job', job.id, 'with name', job.type, 'is done'); }); // add the job to the queue job.save();

In the above example, we define a job with a name email and data object that contains the email subject, recipient email address, and email template name. We also define a processing function that logs a message when the job is completed.

To add the job to the queue, we call the save() method on the job object. Once added to the queue, Kue will process the job in the background.

We can start the Kue worker process to process jobs in the background by running the following command in the terminal:

bashCopy code

node node_modules/kue/bin/kue-worker.js

This will start the worker process, and it will start processing jobs in the queue.

In summary, Kue is a powerful job queue library for Node.js that provides a simple API for handling background job processing. We can use it to process delayed jobs, schedule jobs to run in the future, prioritize jobs, and much more.

44. Parallel Jobs + Mailer

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support