-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLoadPackageArchiveDriver.cs
73 lines (61 loc) · 2.65 KB
/
LoadPackageArchiveDriver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// 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.
namespace NuGet.Insights.Worker.LoadPackageArchive
{
public class LoadPackageArchiveDriver : ICatalogLeafScanBatchDriver
{
private readonly PackageFileService _packageFileService;
private readonly ILogger<LoadPackageArchiveDriver> _logger;
public LoadPackageArchiveDriver(PackageFileService packageFileService, ILogger<LoadPackageArchiveDriver> logger)
{
_packageFileService = packageFileService;
_logger = logger;
}
public async Task InitializeAsync(CatalogIndexScan indexScan)
{
await _packageFileService.InitializeAsync();
}
public Task<CatalogIndexScanResult> ProcessIndexAsync(CatalogIndexScan indexScan)
{
return Task.FromResult(indexScan.OnlyLatestLeaves ? CatalogIndexScanResult.ExpandLatestLeaves : CatalogIndexScanResult.ExpandAllLeaves);
}
public Task<CatalogPageScanResult> ProcessPageAsync(CatalogPageScan pageScan)
{
return Task.FromResult(CatalogPageScanResult.ExpandRemoveDuplicates);
}
public async Task<BatchMessageProcessorResult<CatalogLeafScan>> ProcessLeavesAsync(IReadOnlyList<CatalogLeafScan> leafScans)
{
var failed = new List<CatalogLeafScan>();
foreach (var group in leafScans.GroupBy(x => x.PackageId, StringComparer.OrdinalIgnoreCase))
{
var leafItems = group.Select(x => x.ToPackageIdentityCommit()).ToList();
try
{
await _packageFileService.UpdateBatchAsync(group.Key, leafItems);
}
catch (Exception ex) when (leafScans.Count != 1)
{
_logger.LogError(ex, "Updating package file info failed for {Id} with {Count} versions.", group.Key, leafItems.Count);
failed.AddRange(group);
}
}
return new BatchMessageProcessorResult<CatalogLeafScan>(failed);
}
public Task StartAggregateAsync(CatalogIndexScan indexScan)
{
return Task.CompletedTask;
}
public Task<bool> IsAggregateCompleteAsync(CatalogIndexScan indexScan)
{
return Task.FromResult(true);
}
public Task FinalizeAsync(CatalogIndexScan indexScan)
{
return Task.CompletedTask;
}
public async Task DestroyOutputAsync()
{
await _packageFileService.DestroyAsync();
}
}
}