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

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?