add logs on parse ses hook
This commit is contained in:
@@ -38,6 +38,12 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
|
|
||||||
const mailData = getEmailData(data);
|
const mailData = getEmailData(data);
|
||||||
|
|
||||||
|
logger.setBindings({
|
||||||
|
sesEmailId,
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.info({ mailStatus }, "Parsing ses hook");
|
||||||
|
|
||||||
let email = await db.email.findUnique({
|
let email = await db.email.findUnique({
|
||||||
where: {
|
where: {
|
||||||
sesEmailId,
|
sesEmailId,
|
||||||
@@ -100,6 +106,8 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
WHERE id = ${email.id}
|
WHERE id = ${email.id}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
logger.info("Latest status updated");
|
||||||
|
|
||||||
// Update daily email usage statistics
|
// Update daily email usage statistics
|
||||||
const today = new Date().toISOString().split("T")[0] as string; // Format: YYYY-MM-DD
|
const today = new Date().toISOString().split("T")[0] as string; // Format: YYYY-MM-DD
|
||||||
|
|
||||||
@@ -109,6 +117,8 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
|
|
||||||
// Add emails to suppression list for hard bounces and complaints
|
// Add emails to suppression list for hard bounces and complaints
|
||||||
if (isHardBounced || mailStatus === EmailStatus.COMPLAINED) {
|
if (isHardBounced || mailStatus === EmailStatus.COMPLAINED) {
|
||||||
|
logger.info("Adding emails to suppression list");
|
||||||
|
|
||||||
const recipientEmails = Array.isArray(email.to) ? email.to : [email.to];
|
const recipientEmails = Array.isArray(email.to) ? email.to : [email.to];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -156,6 +166,7 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
"SENT",
|
"SENT",
|
||||||
].includes(mailStatus)
|
].includes(mailStatus)
|
||||||
) {
|
) {
|
||||||
|
logger.info("Updating daily email usage");
|
||||||
const updateField = mailStatus.toLowerCase();
|
const updateField = mailStatus.toLowerCase();
|
||||||
|
|
||||||
await db.dailyEmailUsage.upsert({
|
await db.dailyEmailUsage.upsert({
|
||||||
@@ -193,6 +204,7 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
updateField === "complained" ||
|
updateField === "complained" ||
|
||||||
updateField === "delivered"
|
updateField === "delivered"
|
||||||
) {
|
) {
|
||||||
|
logger.info("Updating cumulated metrics");
|
||||||
await db.cumulatedMetrics.upsert({
|
await db.cumulatedMetrics.upsert({
|
||||||
where: {
|
where: {
|
||||||
teamId_domainId: {
|
teamId_domainId: {
|
||||||
@@ -244,6 +256,8 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("Creating email event");
|
||||||
|
|
||||||
await db.emailEvent.create({
|
await db.emailEvent.create({
|
||||||
data: {
|
data: {
|
||||||
emailId: email.id,
|
emailId: email.id,
|
||||||
@@ -253,6 +267,8 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
logger.info("Email event created");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,7 +399,12 @@ export class SesHookParser {
|
|||||||
);
|
);
|
||||||
|
|
||||||
private static async execute(event: SesEvent) {
|
private static async execute(event: SesEvent) {
|
||||||
|
try {
|
||||||
await parseSesHook(event);
|
await parseSesHook(event);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ error }, "Error parsing ses hook");
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static async queue(data: { event: SesEvent; messageId: string }) {
|
static async queue(data: { event: SesEvent; messageId: string }) {
|
||||||
|
Reference in New Issue
Block a user