diff --git a/src/NuGet.Jobs.Common/JsonConfigurationJob.cs b/src/NuGet.Jobs.Common/JsonConfigurationJob.cs index 948f188cb..b19a70d45 100644 --- a/src/NuGet.Jobs.Common/JsonConfigurationJob.cs +++ b/src/NuGet.Jobs.Common/JsonConfigurationJob.cs @@ -31,6 +31,8 @@ public abstract class JsonConfigurationJob : JobBase private const string ServiceBusConfigurationSectionName = "ServiceBus"; private const string ValidationStorageConfigurationSectionName = "ValidationStorage"; + private bool testDatabaseConnections = true; + public JsonConfigurationJob() : this(null) { @@ -147,19 +149,26 @@ private void ConfigureLibraries(IServiceCollection services) protected virtual void RegisterDatabases(IServiceProvider serviceProvider) { - RegisterDatabaseIfConfigured(serviceProvider); - RegisterDatabaseIfConfigured(serviceProvider); - RegisterDatabaseIfConfigured(serviceProvider); - RegisterDatabaseIfConfigured(serviceProvider); + try + { + RegisterDatabaseIfConfigured(serviceProvider, testDatabaseConnections); + RegisterDatabaseIfConfigured(serviceProvider, testDatabaseConnections); + RegisterDatabaseIfConfigured(serviceProvider, testDatabaseConnections); + RegisterDatabaseIfConfigured(serviceProvider, testDatabaseConnections); + } + finally + { + testDatabaseConnections = false; + } } - private void RegisterDatabaseIfConfigured(IServiceProvider serviceProvider) + private void RegisterDatabaseIfConfigured(IServiceProvider serviceProvider, bool testConnection) where TDbConfiguration : IDbConfiguration { var dbConfiguration = serviceProvider.GetRequiredService>(); if (!string.IsNullOrEmpty(dbConfiguration.Value?.ConnectionString)) { - RegisterDatabase(serviceProvider); + RegisterDatabase(serviceProvider, testConnection); } }