Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
/ NuGet.Jobs Public archive

Commit

Permalink
Only test connection on first iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
chenriksson committed Oct 30, 2018
1 parent dd6949b commit 20785fa
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/NuGet.Jobs.Common/JsonConfigurationJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -147,19 +149,26 @@ private void ConfigureLibraries(IServiceCollection services)

protected virtual void RegisterDatabases(IServiceProvider serviceProvider)
{
RegisterDatabaseIfConfigured<GalleryDbConfiguration>(serviceProvider);
RegisterDatabaseIfConfigured<StatisticsDbConfiguration>(serviceProvider);
RegisterDatabaseIfConfigured<SupportRequestDbConfiguration>(serviceProvider);
RegisterDatabaseIfConfigured<ValidationDbConfiguration>(serviceProvider);
try
{
RegisterDatabaseIfConfigured<GalleryDbConfiguration>(serviceProvider, testDatabaseConnections);
RegisterDatabaseIfConfigured<StatisticsDbConfiguration>(serviceProvider, testDatabaseConnections);
RegisterDatabaseIfConfigured<SupportRequestDbConfiguration>(serviceProvider, testDatabaseConnections);
RegisterDatabaseIfConfigured<ValidationDbConfiguration>(serviceProvider, testDatabaseConnections);
}
finally
{
testDatabaseConnections = false;
}
}

private void RegisterDatabaseIfConfigured<TDbConfiguration>(IServiceProvider serviceProvider)
private void RegisterDatabaseIfConfigured<TDbConfiguration>(IServiceProvider serviceProvider, bool testConnection)
where TDbConfiguration : IDbConfiguration
{
var dbConfiguration = serviceProvider.GetRequiredService<IOptionsSnapshot<TDbConfiguration>>();
if (!string.IsNullOrEmpty(dbConfiguration.Value?.ConnectionString))
{
RegisterDatabase<TDbConfiguration>(serviceProvider);
RegisterDatabase<TDbConfiguration>(serviceProvider, testConnection);
}
}

Expand Down

0 comments on commit 20785fa

Please sign in to comment.