Last active
June 19, 2020 08:01
-
-
Save shivamv12/314efb33f4665d91ba7979c854a4ce99 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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