Skip to content

Commit 6602187

Browse files
committed
WIP
1 parent d13a635 commit 6602187

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

packages/core/src/events/handlers/sendIssueEscalatingHandler.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const BATCH_SIZE = 100 // Batch size can be up to 1000 in mailgun
1717
async function findNotificableMembers(workspace: Workspace) {
1818
return database
1919
.select({
20-
id: users.id,
20+
userId: users.id,
2121
email: users.email,
2222
name: users.name,
2323
membershipId: memberships.id,
@@ -33,7 +33,6 @@ async function findNotificableMembers(workspace: Workspace) {
3333
.orderBy(asc(users.createdAt))
3434
}
3535

36-
// TODO: Refactor common batching logic with other mailers
3736
async function sendEmail({
3837
workspace,
3938
issue,
@@ -79,21 +78,14 @@ async function sendEmail({
7978

8079
// Send emails in batches using the new sendInBatches method
8180
await mailer.sendInBatches({
82-
addresses: members,
83-
sendOptions: async (batch) => {
84-
const result = await mailer.send({
81+
addressList: members,
82+
sendOptions: async (batch) =>
83+
mailer.send({
8584
to: batch.to,
8685
recipientVariables: batch.recipientVariables,
8786
currentWorkspace: workspace,
8887
issue: issueData,
89-
})
90-
91-
if (result.error) {
92-
throw result.error
93-
}
94-
95-
return result.value
96-
},
88+
}),
9789
context: {
9890
mailName: 'issue_escalation_email',
9991
issueId: issue.id,

packages/core/src/mailers/mailers/Mailer.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import SMTPTransport from 'nodemailer/lib/smtp-transport'
66
import { Result, TypedResult } from '../../lib/Result'
77
import { captureException } from '../../utils/datadogCapture'
88
import { createAdapter } from './adapters'
9-
import { AddressItem, buildBatchRecipients } from './buildBatchRecipients'
9+
import {
10+
AddressItem,
11+
buildBatchRecipients,
12+
RecipientBatch,
13+
} from './buildBatchRecipients'
1014

1115
/**
1216
* Batch sending options for Mailgun.
@@ -126,10 +130,9 @@ export default abstract class Mailer {
126130
batchSize = 100,
127131
}: {
128132
addressList: AddressItem[]
129-
sendOptions: (batch: {
130-
to: string[]
131-
recipientVariables: Record<string, Record<string, unknown>>
132-
}) => Promise<TypedResult<SMTPTransport.SentMessageInfo, Error>>
133+
sendOptions: (
134+
batch: RecipientBatch,
135+
) => Promise<TypedResult<SMTPTransport.SentMessageInfo, Error>>
133136
context: {
134137
mailName: string
135138
[key: string]: unknown

packages/core/src/mailers/mailers/buildBatchRecipients.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ export function buildBatchRecipients({
3535

3636
return batches
3737
}
38+
39+
export type RecipientBatch = ReturnType<typeof buildBatchRecipients>[number]

packages/core/src/mailers/mailers/mailers/issues/IssueEscalatingMailer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import IssueEscalatingMail, {
88
IssueEscalatingMailProps,
99
} from '@latitude-data/emails/IssueEscalatingMail'
1010
import Mailer from '../../Mailer'
11+
import { RecipientBatch } from '../../buildBatchRecipients'
1112

1213
export type SendIssueEscalatingMailOptions = {
1314
to: Mail.Options['to']
14-
recipientVariables?: Record<string, Record<string, unknown>>
15+
recipientVariables: RecipientBatch['recipientVariables']
1516
currentWorkspace: NotificiationsLayoutProps['currentWorkspace']
1617
issue: IssueEscalatingMailProps['issue']
1718
}

packages/core/src/mailers/mailers/mailers/weeklyEmail/WeeklyEmailMailer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import WeeklyEmailMail, {
88
WeeklyEmailMailProps,
99
} from '@latitude-data/emails/WeeklyEmailMail'
1010
import Mailer from '../../Mailer'
11+
import { RecipientBatch } from '../../buildBatchRecipients'
1112

1213
export type SendWeeklyEmailMailOptions = {
1314
to: Mail.Options['to']
14-
recipientVariables?: Record<string, Record<string, unknown>>
15+
recipientVariables: RecipientBatch['recipientVariables']
1516
currentWorkspace: NotificiationsLayoutProps['currentWorkspace']
1617
logs: WeeklyEmailMailProps['logs']
1718
issues: WeeklyEmailMailProps['issues']

0 commit comments

Comments
 (0)