Skip to content

Instantly share code, notes, and snippets.

@shivamv12
Last active June 19, 2020 08:01
Show Gist options
  • Save shivamv12/314efb33f4665d91ba7979c854a4ce99 to your computer and use it in GitHub Desktop.
Save shivamv12/314efb33f4665d91ba7979c854a4ce99 to your computer and use it in GitHub Desktop.
const Queue = require('bull');
const sendMail = require('../utils/sendMail');
const welcomeMailJob = async (payload) => {
/** Initializing the Queue */
const sendMailQueue = new Queue('sendMail', {
redis: {
host: process.env.LOCAL_HOST,
port: process.env.REDIS_PORT,
},
});
/** Build data & options object */
const data = {
to: payload.email,
subject: '🌍 Warm welcome from Company',
body: "Welcome to this company.",
};
const options = {delay: 5000, attempts: 3};
/** Adding a Job to the Queue */
sendMailQueue.add(data, options);
/** Consumer */
sendMailQueue.process(async (job) => await sendMail(job.data));
}
module.exports = welcomeMailJob;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment