feat: Implement draft version of reset password email (#949)

This commit is contained in:
Ömer Faruk Aydın
2023-02-24 00:25:10 +01:00
committed by GitHub
parent bd02b7574a
commit a0815b06a6
9 changed files with 141 additions and 1 deletions

View File

@@ -0,0 +1,37 @@
import { Worker } from 'bullmq';
import redisConfig from '../config/redis';
import logger from '../helpers/logger';
import mailer from '../helpers/mailer.ee';
import compileEmail from '../helpers/compile-email.ee';
import appConfig from '../config/app';
export const worker = new Worker(
'email',
async (job) => {
const { email, subject, templateName, params } = job.data;
await mailer.sendMail({
to: email,
from: appConfig.fromEmail,
subject: subject,
html: compileEmail(templateName, params),
});
},
{ connection: redisConfig }
);
worker.on('completed', (job) => {
logger.info(
`JOB ID: ${job.id} - ${job.data.subject} email sent to ${job.data.email}!`
);
});
worker.on('failed', (job, err) => {
logger.info(
`JOB ID: ${job.id} - ${job.data.subject} email to ${job.data.email} has failed to send with ${err.message}`
);
});
process.on('SIGTERM', async () => {
await worker.close();
});