-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6671035
commit b535756
Showing
8 changed files
with
90 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,43 @@ | ||
import { Handler } from "aws-lambda"; | ||
import { KafkaEvent, KafkaRecord } from "shared-types"; | ||
import { ErrorType, getTopic, logError } from "../libs"; | ||
import { KafkaEvent } from "shared-types"; | ||
import { ErrorType, getTopic, logError } from "libs"; | ||
import { | ||
insertOneMacRecordsFromKafkaIntoMako, | ||
insertNewSeatoolRecordsFromKafkaIntoMako, | ||
syncSeatoolRecordDatesFromKafkaWithMako, | ||
} from "./sinkMainProcessors"; | ||
|
||
export const handler: Handler<KafkaEvent> = async (event) => { | ||
const eventInfo = JSON.stringify(event, null, 2); | ||
console.log(`Received event: ${eventInfo}`); | ||
const prettifiedEventJSON = JSON.stringify(event, null, 2); | ||
|
||
console.log(`event: ${prettifiedEventJSON}`); | ||
|
||
try { | ||
// Process each topicPartition concurrently | ||
await Promise.all( | ||
Object.entries(event.records).map(async ([topicPartition, records]) => | ||
processTopicPartition(topicPartition, records), | ||
), | ||
Object.entries(event.records).map(async ([topicPartition, records]) => { | ||
const topic = getTopic(topicPartition); | ||
|
||
console.log(`topic: ${topic}`); | ||
|
||
switch (topic) { | ||
case "aws.onemac.migration.cdc": | ||
return insertOneMacRecordsFromKafkaIntoMako(records, topicPartition); | ||
|
||
case "aws.seatool.ksql.onemac.three.agg.State_Plan": | ||
return insertNewSeatoolRecordsFromKafkaIntoMako(records, topicPartition); | ||
|
||
case "aws.seatool.debezium.changed_date.SEA.dbo.State_Plan": | ||
return syncSeatoolRecordDatesFromKafkaWithMako(records, topicPartition); | ||
|
||
default: | ||
logError({ type: ErrorType.BADTOPIC }); | ||
throw new Error(`topic (${topicPartition}) is invalid`); | ||
} | ||
}), | ||
); | ||
} catch (error) { | ||
logError({ type: ErrorType.UNKNOWN, metadata: { event: eventInfo } }); | ||
logError({ type: ErrorType.UNKNOWN, metadata: { event: prettifiedEventJSON } }); | ||
|
||
throw error; | ||
} | ||
}; | ||
|
||
async function processTopicPartition( | ||
topicPartition: string, | ||
records: KafkaRecord[], | ||
): Promise<void> { | ||
const topic = getTopic(topicPartition); | ||
if (!topic) { | ||
logError({ type: ErrorType.BADTOPIC }); | ||
throw new Error(`Invalid topic: ${topicPartition}`); | ||
} | ||
|
||
switch (topic) { | ||
case "aws.onemac.migration.cdc": | ||
await insertOneMacRecordsFromKafkaIntoMako(records, topicPartition); | ||
break; | ||
case "aws.seatool.ksql.onemac.three.agg.State_Plan": | ||
await insertNewSeatoolRecordsFromKafkaIntoMako(records, topicPartition); | ||
break; | ||
case "aws.seatool.debezium.changed_date.SEA.dbo.State_Plan": | ||
await syncSeatoolRecordDatesFromKafkaWithMako(records, topicPartition); | ||
break; | ||
default: | ||
logError({ type: ErrorType.BADTOPIC, metadata: { topic } }); | ||
throw new Error(`Unsupported topic: ${topic}`); | ||
} | ||
} |