Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions backend/src/entities/cron-jobs/cron-jobs.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ export class CronJobsService {
Constants.EXCEPTIONS_CHANNELS,
);
} else {
// const mailingResultToString = this.sentEmailsToSimpleString(mailingResults);
await slackPostMessage(JSON.stringify(mailingResults), Constants.EXCEPTIONS_CHANNELS);
// await this.sendEmailResultsToSlack(mailingResults);
// await slackPostMessage(JSON.stringify(mailingResults), Constants.EXCEPTIONS_CHANNELS);
await this.sendEmailResultsToSlack(mailingResults);
await slackPostMessage(
`morning cron finished at ${Constants.CURRENT_TIME_FORMATTED()}`,
Constants.EXCEPTIONS_CHANNELS,
Expand Down Expand Up @@ -133,15 +132,10 @@ export class CronJobsService {
for (let i = 0; i < results.length; i += chunkSize) {
const chunk = results.slice(i, i + chunkSize);
const message = this.emailCronResultToSlackString(chunk);
if (!message) {
continue;
}
await slackPostMessage(message, Constants.EXCEPTIONS_CHANNELS);
}
}

private sentEmailsToSimpleString(results: Array<ICronMessagingResults>): string | null {
const emailsSent = results.map((result) => {
return result.accepted && result.accepted.length > 0 ? result.accepted.join(', ') : '-';
});
const emailsSentString = emailsSent.join(', \n');
return emailsSentString;
}
}
30 changes: 15 additions & 15 deletions backend/src/entities/email/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,9 @@ export class EmailService {
public async sendRemindersToUsers(userEmails: Array<string>): Promise<Array<ICronMessagingResults>> {
const queue = new PQueue({ concurrency: 8 });
const mailingResults: Array<SMTPTransport.SentMessageInfo | void> = await Promise.all(
userEmails.map(async (email: string, index) => {
userEmails.map(async (email: string) => {
return await queue.add(async () => {
const result = await this.sendReminderToUser(email);
console.info(`${index} email sending result ${JSON.stringify(result)}`);
return result;
return await this.sendReminderToUser(email);
});
}),
);
Expand Down Expand Up @@ -275,16 +273,18 @@ export class EmailService {
}

private buildMailingResults(results: Array<SMTPTransport.SentMessageInfo | void>): Array<ICronMessagingResults> {
return results.map((result) => {
if (!result) {
return;
}
const { messageId, accepted, rejected } = result;
return {
messageId: messageId ? messageId : undefined,
accepted: accepted ? accepted : undefined,
rejected: rejected ? rejected : undefined,
};
});
return results
.map((result) => {
if (!result) {
return;
}
const { messageId, accepted, rejected } = result;
return {
messageId: messageId ? messageId : undefined,
accepted: accepted ? accepted : undefined,
rejected: rejected ? rejected : undefined,
};
})
.filter((result) => !!result);
}
}