From a1720b2d4f2d8fe8dc6d43e8aec6fe57112a08dd Mon Sep 17 00:00:00 2001 From: Marek Matulka Date: Mon, 13 Jan 2025 12:22:43 +0000 Subject: [PATCH] DP-1013: Add a falback if ElastiCache fails to start --- .../ElastiCacheExtensions.cs | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Libraries/CO.CDP.AwsServices/ElastiCacheExtensions.cs b/Libraries/CO.CDP.AwsServices/ElastiCacheExtensions.cs index a919cf287..b579156b3 100644 --- a/Libraries/CO.CDP.AwsServices/ElastiCacheExtensions.cs +++ b/Libraries/CO.CDP.AwsServices/ElastiCacheExtensions.cs @@ -11,15 +11,22 @@ public static IServiceCollection AddSharedSessions(this IServiceCollection servi { if (configuration.GetValue("Features:SharedSessions")) { - Console.WriteLine("SharedSession is enabled."); - services.AddElastiCacheService(); - } - else - { - Console.WriteLine("SharedSession is disabled."); - services.AddDistributedMemoryCache(); + try + { + services.AddElastiCacheService(); + Console.WriteLine("SharedSession is enabled."); + + return services; + } + catch (Exception ex) + { + Console.WriteLine("SharedSession failed to start with: " + ex.Message); + } } + services.AddDistributedMemoryCache(); + Console.WriteLine("SharedSession is disabled."); + return services; }