From 20785fa56e2bd7cc9c6e7046e6679e2d41ac15ce Mon Sep 17 00:00:00 2001 From: Christy Henriksson Date: Tue, 30 Oct 2018 12:36:07 -0700 Subject: [PATCH] Only test connection on first iteration --- src/NuGet.Jobs.Common/JsonConfigurationJob.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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); } }