/**
* Reloads message queue configuration with retry logic.
* @param {function} reloadConfig - Function to reload the configuration. Should return a promise.
* @param {number} maxRetries - Maximum number of retry attempts.
* @param {number} delayMs - Delay between retries in milliseconds.
* @returns {Promise<void>} - A promise that resolves when the configuration is successfully reloaded or rejects after maxRetries attempts.
*/
async function reloadMessageQueueConfig(reloadConfig, maxRetries = 3, delayMs = 1000) {
let retries = 0;
while (retries < maxRetries) {
try {
// Attempt to reload the configuration.
await reloadConfig();
console.log("Message queue configuration reloaded successfully.");
return; // Exit the function if successful.
} catch (error) {
console.error(`Failed to reload message queue configuration. Retry attempt ${retries + 1}/${maxRetries}:`, error);
retries++;
if (retries < maxRetries) {
// Wait before retrying.
await new Promise(resolve => setTimeout(resolve, delayMs));
} else {
// Reached the maximum number of retries.
console.error("Failed to reload message queue configuration after multiple retries.");
throw error; // Re-throw the error to signal failure.
}
}
}
}
// Example usage (replace with your actual reloadConfig function)
// async function myReloadConfig() {
// // Replace with your logic to reload the message queue configuration
// console.log("Reloading config...");
// await new Promise(resolve => setTimeout(resolve, 500)); // Simulate a delay
// console.log("Config reloaded.");
// }
// reloadMessageQueueConfig(myReloadConfig, 5, 2000)
// .then(() => console.log("Configuration reload process completed."))
// .catch(err => console.error("Configuration reload failed after all retries:", err));
Add your comment