Skip to content

Commit

Permalink
fix(kafka cleanup): Fix error with kafka cleanup by adding a loop (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdial89f authored Nov 30, 2023
1 parent cdfd578 commit 86d75e6
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/services/data/handlers/cleanupKafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const handler = async function (
const responseData: any = {};

Check warning on line 11 in src/services/data/handlers/cleanupKafka.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
let responseStatus: ResponseStatus = SUCCESS;
try {
if (event.RequestType === "Create" || event.RequestType == "Update") {
if (event.RequestType === "Create" || event.RequestType === "Update") {
console.log("This resource does nothing on Create and Update events.");
} else if (event.RequestType === "Delete") {
const BrokerString: string = event.ResourceProperties.BrokerString;
Expand All @@ -20,7 +20,30 @@ export const handler = async function (
console.log(
`Attempting a delete for each of the following patterns: ${TopicPatternsToDelete}`
);
await topics.deleteTopics(BrokerString, TopicPatternsToDelete);

const maxRetries = 10;
const retryDelay = 10000; //10s
let retries = 0;
let success = false;
while (!success && retries < maxRetries) {
try {
await topics.deleteTopics(BrokerString, TopicPatternsToDelete);
success = true;
} catch (error) {
console.error(`Error in deleteTopics operation: ${error.message}`);
retries++;
console.log(
`Retrying in ${
retryDelay / 1000
} seconds (Retry ${retries}/${maxRetries})`
);
await new Promise((resolve) => setTimeout(resolve, retryDelay));
}
}
if (!success) {
console.error(`Failed to delete topics after ${maxRetries} retries.`);
responseStatus = FAILED;
}
}
} catch (error) {
console.error(error);
Expand Down

0 comments on commit 86d75e6

Please sign in to comment.