Skip to content

Commit

Permalink
figuring out logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jdinh8124 committed Jan 23, 2025
1 parent bda0f1f commit a1f9051
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions lib/lambda/processEmails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export const handler: Handler<KafkaEvent> = async (event) => {

export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEmailConfig) {
console.log('before process record')
console.log("processRecord called with kafkaRecord: ", JSON.stringify(kafkaRecord, null, 2));
const { key, value, timestamp } = kafkaRecord;
const id: string = decodeBase64WithUtf8(key);

if (kafkaRecord.topic === "aws.seatool.ksql.onemac.three.agg.State_Plan") {
const record = JSON.parse(decodeBase64WithUtf8(kafkaRecord.value))
console.log('inside process record', record)
Expand All @@ -121,7 +125,14 @@ export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEma
//send email
console.log(safeSeatoolRecord.data?.cmsStatus, "seatool status is withdrawn")

// await processAndSendEmails(record, id, config);
console.log(record,id, config)

try {
await processAndSendEmails(record, id, config);
} catch (error) {
console.error("Error processing record:", JSON.stringify(error, null, 2));
throw error;
}
}
return
}
Expand All @@ -136,13 +147,11 @@ export async function processRecord(kafkaRecord: KafkaRecord, config: ProcessEma
// then we can get the email template and send it


console.log("processRecord called with kafkaRecord: ", JSON.stringify(kafkaRecord, null, 2));
const { key, value, timestamp } = kafkaRecord;

if (typeof key !== "string") {
console.log("key is not a string ", JSON.stringify(key, null, 2));
throw new Error("Key is not a string");
}
const id: string = decodeBase64WithUtf8(key);

if (!value) {
console.log("Tombstone detected. Doing nothing for this event");
Expand Down
4 changes: 2 additions & 2 deletions lib/stacks/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export class Email extends cdk.NestedStack {

alarm.addAlarmAction(new cdk.aws_cloudwatch_actions.SnsAction(alarmTopic));

new CfnEventSourceMapping(this, "SinkSESTrigger1", {
new CfnEventSourceMapping(this, "SinkSESTrigger5", {
batchSize: 1,
enabled: true,
selfManagedEventSource: {
Expand Down Expand Up @@ -250,7 +250,7 @@ export class Email extends cdk.NestedStack {
},
});

new CfnEventSourceMapping(this, "SinkSESTrigger2", {
new CfnEventSourceMapping(this, "SinkSESTrigger6", {
batchSize: 1,
enabled: true,
selfManagedEventSource: {
Expand Down

0 comments on commit a1f9051

Please sign in to comment.