Skip to content

Commit

Permalink
docs: Update email sending functionality and dependencies with BullMQ
Browse files Browse the repository at this point in the history
  • Loading branch information
wajeht committed Aug 8, 2024
1 parent 058e7de commit 288d734
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"cSpell.words": ["healthz", "knexfile", "tseslint", "wajeht"]
"cSpell.words": ["bullmq", "healthz", "knexfile", "tseslint", "wajeht"]
}
181 changes: 180 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
},
"dependencies": {
"bcrypt": "^5.1.1",
"bullmq": "^5.12.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
Expand Down
Empty file added src/jobs/discord.job.ts
Empty file.
30 changes: 30 additions & 0 deletions src/jobs/email.job.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Queue, Worker } from 'bullmq';
import { redis } from '../database/db';
import { sendEmail } from './utils/email';

const queueName = 'sendEmailQueue';

export const sendEmailQueue = new Queue(queueName, {
connection: redis,
});

const processSendEmailJob = async (job: any) => {

Check warning on line 11 in src/jobs/email.job.ts

View workflow job for this annotation

GitHub Actions / ESLint (22.x)

Unexpected any. Specify a different type
try {
job.updateProgress(0);
await sendEmail({ tenant: job.data.tenant, coach: job.data.coach });
job.updateProgress(100);
console.info(`Email successfully sent for tenant: ${job.data.tenant}`);
} catch (error) {
console.error(`Failed to send email for tenant: ${job.data.tenant}`, error);
}
};

new Worker(queueName, processSendEmailJob, { connection: redis });

export async function sendApproveTenantEmailJob(data: any) {

Check warning on line 24 in src/jobs/email.job.ts

View workflow job for this annotation

GitHub Actions / ESLint (22.x)

Unexpected any. Specify a different type
try {
await sendEmailQueue.add('sendEmailJob', data);
} catch (error) {
console.error(`Failed to add job to queue for tenant: ${data.tenant}`, error);
}
}
Empty file added src/jobs/jobs.ts
Empty file.
Empty file added src/jobs/notification.job.ts
Empty file.
Empty file added src/jobs/sms.job.ts
Empty file.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/notification/email.ts → src/jobs/utils/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nodemailer from 'nodemailer';

import { emailConfig, appConfig } from '../config';
import { emailConfig, appConfig } from '../../config';

const transporter = nodemailer.createTransport(emailConfig);

Expand All @@ -15,7 +15,7 @@ interface SendMailOptions {

const template = `<h1>hello world</h1>`;

Check warning on line 16 in src/jobs/utils/email.ts

View workflow job for this annotation

GitHub Actions / ESLint (22.x)

'template' is assigned a value but never used. Allowed unused vars must match /^_/u

export async function send({
export async function sendEmail({
to = `${domain} <${emailConfig.alias}>`,
subject,
html: template,
Expand Down
2 changes: 1 addition & 1 deletion src/notification/sms.ts → src/jobs/utils/sms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import twilio from 'twilio';
import { smsConfig } from '../config';
import { smsConfig } from '../../config';

const client = twilio(smsConfig.accountSid, smsConfig.authToken);

Expand Down

0 comments on commit 288d734

Please sign in to comment.