Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(kafka cleanup): Fix error with kafka cleanup by adding a retry loop #234

Merged
merged 1 commit into from
Nov 30, 2023
Merged
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
27 changes: 25 additions & 2 deletions src/services/data/handlers/cleanupKafka.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
context: Context
): Promise<void> {
console.log("Request:", JSON.stringify(event, undefined, 2));
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 @@
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
Loading