Merged in feature/IO-3096-GlobalNotifications (pull request #2173)

IO-3166-Global-Notifications-Part-2 - Improved GetRedisNodesFromAWS
This commit is contained in:
Dave Richer
2025-03-07 20:12:28 +00:00

View File

@@ -141,9 +141,24 @@ const getRedisNodesFromAWS = async () => {
const response = await client.send(command);
const cacheClusters = response.CacheClusters;
return cacheClusters.flatMap((cluster) =>
cluster.CacheNodes.map((node) => `${node.Endpoint.Address}:${node.Endpoint.Port}`)
);
// Ensure cacheClusters exists and is an array
if (!cacheClusters || !Array.isArray(cacheClusters) || cacheClusters.length === 0) {
logger.log(`No cache clusters found for cluster id ${process.env.REDIS_CLUSTER_ID}`, "ERROR", "redis", "api");
return [];
}
// Process each cluster
return cacheClusters.flatMap((cluster) => {
if (cluster.CacheNodes && Array.isArray(cluster.CacheNodes)) {
// Map nodes to address strings
const addresses = cluster.CacheNodes.map((node) => `${node.Endpoint.Address}:${node.Endpoint.Port}`);
// Debug log node addresses
logger.log(`Cluster node addresses: ${addresses.join(", ")}`, "DEBUG", "redis", "api");
// Return only those addresses that start with the current cluster id
return addresses.filter((address) => address.startsWith(process.env.REDIS_CLUSTER_ID));
}
return [];
});
} catch (err) {
logger.log(`Error fetching Redis nodes from AWS:`, "ERROR", "redis", "api", {
message: err?.message,