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

Only test connection on first iteration #603

Merged
merged 1 commit into from
Nov 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to log in AI if the test connection was invoked ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test connection results are logged to AI

}
}

Expand Down