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

Merge branch 'master' into dev #737

Merged
merged 4 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;

namespace Search.GenerateAuxiliaryData
{
public class InitializationConfiguration
Expand All @@ -12,5 +14,7 @@ public class InitializationConfiguration
public string PrimaryDestination { get; set; }

public string DestinationContainerName { get; set; }

public TimeSpan SqlCommandTimeout { get; set; } = TimeSpan.FromMinutes(1);
}
}
9 changes: 6 additions & 3 deletions src/Search.GenerateAuxiliaryData/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public override void Init(IServiceContainer serviceContainer, IDictionary<string
OpenSqlConnectionAsync<GalleryDbConfiguration>,
destinationContainer,
ScriptVerifiedPackages,
OutputNameVerifiedPackages),
OutputNameVerifiedPackages,
Configuration.SqlCommandTimeout),

new NestedJArrayExporter(
LoggerFactory.CreateLogger<NestedJArrayExporter>(),
Expand All @@ -67,14 +68,16 @@ public override void Init(IServiceContainer serviceContainer, IDictionary<string
ScriptOwners,
OutputNameOwners,
Col0Owners,
Col1Owners),
Col1Owners,
Configuration.SqlCommandTimeout),

new RankingsExporter(
LoggerFactory.CreateLogger<RankingsExporter>(),
OpenSqlConnectionAsync<StatisticsDbConfiguration>,
destinationContainer,
ScriptRankingsTotal,
OutputNameRankings),
OutputNameRankings,
Configuration.SqlCommandTimeout),

new BlobStorageExporter(
LoggerFactory.CreateLogger<BlobStorageExporter>(),
Expand Down
8 changes: 6 additions & 2 deletions src/Search.GenerateAuxiliaryData/NestedJArrayExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ public NestedJArrayExporter(
ILogger<NestedJArrayExporter> logger,
Func<Task<SqlConnection>> openSqlConnectionAsync,
CloudBlobContainer defaultDestinationContainer,
string defaultSqlScript, string defaultName, string defaultCol0, string defaultCol1)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName)
string defaultSqlScript,
string defaultName,
string defaultCol0,
string defaultCol1,
TimeSpan commandTimeout)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName, commandTimeout)
{
Col0 = defaultCol0;
Col1 = defaultCol1;
Expand Down
6 changes: 3 additions & 3 deletions src/Search.GenerateAuxiliaryData/RankingsExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public RankingsExporter(
Func<Task<SqlConnection>> openSqlConnectionAsync,
CloudBlobContainer defaultDestinationContainer,
string defaultRankingsScript,
string defaultName)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName)
string defaultName,
TimeSpan commandTimeout)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName, commandTimeout)
{
_rankingsTotalScript = defaultRankingsScript;
}
Expand All @@ -34,7 +35,6 @@ protected override JContainer GetResultOfQuery(SqlConnection connection)
{
var rankingsTotalCommand = GetEmbeddedSqlCommand(connection, _rankingsTotalScript);
rankingsTotalCommand.Parameters.AddWithValue(_rankingCountParameterName, _rankingCount);
rankingsTotalCommand.CommandTimeout = 60;

return GetRankings(rankingsTotalCommand.ExecuteReader());
}
Expand Down
11 changes: 8 additions & 3 deletions src/Search.GenerateAuxiliaryData/SqlExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,32 @@ public abstract class SqlExporter : Exporter

private Func<Task<SqlConnection>> OpenSqlConnectionAsync { get; }

private readonly TimeSpan _commandTimeout;

public SqlExporter(
ILogger<SqlExporter> logger,
Func<Task<SqlConnection>> openSqlConnectionAsync,
CloudBlobContainer defaultDestinationContainer,
string defaultName)
string defaultName,
TimeSpan commandTimeout)
: base(logger, defaultDestinationContainer, defaultName)
{
_logger = logger;
OpenSqlConnectionAsync = openSqlConnectionAsync;
_commandTimeout = commandTimeout;
}

[SuppressMessage("Microsoft.Security", "CA2100", Justification = "Query string comes from embedded resource, not user input.")]
protected static SqlCommand GetEmbeddedSqlCommand(SqlConnection connection, string resourceName)
protected SqlCommand GetEmbeddedSqlCommand(SqlConnection connection, string resourceName)
{
using (var reader = new StreamReader(_executingAssembly.GetManifestResourceStream(_assemblyName + "." + resourceName)))
{
var commandText = reader.ReadToEnd();

return new SqlCommand(commandText, connection)
{
CommandType = CommandType.Text
CommandType = CommandType.Text,
CommandTimeout = (int)_commandTimeout.TotalSeconds,
};
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Search.GenerateAuxiliaryData/VerifiedPackagesExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ public VerifiedPackagesExporter(
Func<Task<SqlConnection>> openSqlConnectionAsync,
CloudBlobContainer defaultDestinationContainer,
string defaultVerifiedPackagesScript,
string defaultName)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName)
string defaultName,
TimeSpan commandTimeout)
: base(logger, openSqlConnectionAsync, defaultDestinationContainer, defaultName, commandTimeout)
{
_verifiedPackagesScript = defaultVerifiedPackagesScript;
}

protected override JContainer GetResultOfQuery(SqlConnection connection)
{
var verifiedPackagesCommand = GetEmbeddedSqlCommand(connection, _verifiedPackagesScript);
verifiedPackagesCommand.CommandTimeout = 60;

SqlDataReader reader = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ private static RankingsExporter CreateExporter()
openSqlConnectionAsync: () => null,
defaultDestinationContainer: new CloudBlobContainer(new Uri("https://nuget.org")),
defaultRankingsScript: "b",
defaultName: "c");
defaultName: "c",
commandTimeout: TimeSpan.FromSeconds(10));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ private static VerifiedPackagesExporter CreateExporter()
openSqlConnectionAsync: () => null,
defaultDestinationContainer: new CloudBlobContainer(new Uri("https://nuget.org")),
defaultVerifiedPackagesScript: "b",
defaultName: "c");
defaultName: "c",
commandTimeout: TimeSpan.FromSeconds(10));
}
}
}