This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLoadPackageReadmeDriver.cs
More file actions
78 lines (65 loc) · 2.77 KB
/
LoadPackageReadmeDriver.cs
File metadata and controls
78 lines (65 loc) · 2.77 KB
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
74
75
76
77
78
// 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.LoadPackageReadme
{
public class LoadPackageReadmeDriver : ICatalogLeafScanBatchDriver
{
private readonly PackageReadmeService _packageReadmeService;
private readonly ILogger<LoadPackageReadmeDriver> _logger;
public LoadPackageReadmeDriver(PackageReadmeService packageReadmeService, ILogger<LoadPackageReadmeDriver> logger)
{
_packageReadmeService = packageReadmeService;
_logger = logger;
}
public async Task InitializeAsync()
{
await _packageReadmeService.InitializeAsync();
}
public Task InitializeAsync(CatalogIndexScan indexScan)
{
return Task.CompletedTask;
}
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 _packageReadmeService.UpdateBatchFromLeafItemsAsync(group.Key, leafItems);
}
catch (Exception ex) when (leafScans.Count != 1)
{
_logger.LogError(ex, "Updating package readme 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 _packageReadmeService.DestroyAsync();
}
}
}