Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agr blobs #8517

Merged
merged 8 commits into from
Apr 27, 2021
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
2 changes: 1 addition & 1 deletion src/NuGetGallery/App_Start/AppActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private static void BackgroundJobsPostStart(IAppConfiguration configuration)
if (cloudDownloadCountService != null)
{
// Perform initial refresh + schedule new refreshes every 15 minutes
HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.Refresh());
HostingEnvironment.QueueBackgroundWorkItem(_ => cloudDownloadCountService.RefreshAsync());
jobs.Add(new CloudDownloadCountServiceRefreshJob(TimeSpan.FromMinutes(15), cloudDownloadCountService));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public CloudDownloadCountServiceRefreshJob(TimeSpan interval, CloudDownloadCount

public override Task Execute()
{
return new Task(async () => { await _downloadCountService.Refresh(); });
return new Task(async () => { await _downloadCountService.RefreshAsync(); });
}
}
}
10 changes: 5 additions & 5 deletions src/NuGetGallery/Services/CloudDownloadCountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public bool TryGetDownloadCountForPackage(string id, string version, out int dow
return false;
}

public async Task Refresh()
public async Task RefreshAsync()
{
bool shouldRefresh = false;
lock (_refreshLock)
Expand All @@ -104,7 +104,7 @@ public async Task Refresh()
try
{
var stopwatch = Stopwatch.StartNew();
await RefreshCore();
await RefreshCoreAsync();
stopwatch.Stop();
_telemetryService.TrackDownloadJsonRefreshDuration(stopwatch.ElapsedMilliseconds);

Expand Down Expand Up @@ -148,19 +148,19 @@ protected virtual int CalculateSum(ConcurrentDictionary<string, int> versions)
/// This method is added for unit testing purposes. It can return a null stream if the blob does not exist
/// and assumes the caller will properly dispose of the returned stream.
/// </summary>
protected virtual async Task<Stream> GetBlobStream()
protected virtual async Task<Stream> GetBlobStreamAsync()
{
var blob = GetBlobReference();
return await blob.OpenReadIfExistsAsync();
}

private async Task RefreshCore()
private async Task RefreshCoreAsync()
{
try
{
// The data in downloads.v1.json will be an array of Package records - which has Id, Array of Versions and download count.
// Sample.json : [["AutofacContrib.NSubstitute",["2.4.3.700",406],["2.5.0",137]],["Assman.Core",["2.0.7",138]]....
using (var blobStream = await GetBlobStream())
using (var blobStream = await GetBlobStreamAsync())
{
if (blobStream == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public async Task ReturnsZeroWhenIdDoesNotExist(string inputId, string contentId
{
// Arrange
_content = $"[[\"{contentId}\",[\"4.6.0\",23],[\"4.6.2\",42]]";
await _target.Refresh();
await _target.RefreshAsync();

// Act
var found = _target.TryGetDownloadCountForPackageRegistration(inputId, out var actual);
Expand All @@ -59,7 +59,7 @@ public async Task ReturnsSumOfVersionsWhenIdExists(string inputId, string conten
{
// Arrange
_content = $"[[\"{contentId}\",[\"4.6.0\",23],[\"4.6.2\",42]]";
await _target.Refresh();
await _target.RefreshAsync();

// Act
var found = _target.TryGetDownloadCountForPackageRegistration(inputId, out var actual);
Expand Down Expand Up @@ -94,7 +94,7 @@ private async Task LoadNewVersionsAsync(string id, TimeSpan duration)
iteration++;
var version = $"0.0.0-beta{iteration}";
_content = $"[[\"{id}\",[\"{version}\",1]]";
await _target.Refresh();
await _target.RefreshAsync();
await Task.Delay(5);
}
}
Expand All @@ -117,7 +117,7 @@ public class TheTryGetDownloadCountForPackageMethod : BaseFacts
public async Task ReturnsZeroWhenVersionDoesNotExist()
{
// Arrange
await _target.Refresh();
await _target.RefreshAsync();

// Act
var found = _target.TryGetDownloadCountForPackage("NuGet.Versioning", "9.9.9", out var actual);
Expand All @@ -131,7 +131,7 @@ public async Task ReturnsZeroWhenVersionDoesNotExist()
public async Task ReturnsCountWhenVersionExists()
{
// Arrange
await _target.Refresh();
await _target.RefreshAsync();

// Act
var found = _target.TryGetDownloadCountForPackage("NuGet.Versioning", "4.6.0", out var actual);
Expand Down Expand Up @@ -188,7 +188,7 @@ protected override int CalculateSum(ConcurrentDictionary<string, int> versions)
return _baseFacts._calculateSum(versions);
}

protected override Task<Stream> GetBlobStream()
protected override Task<Stream> GetBlobStreamAsync()
{
if (_baseFacts._content == null)
{
Expand Down