Retry source requests
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m4s
Build / Build Nuget package (NuGet) (push) Successful in 1m6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m10s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m18s
Build / Build Launcher (push) Successful in 1m54s

Handle missing sources
Minor Optimizations
Move thread pool improvement to debug while we fix it
This commit is contained in:
2025-06-01 11:11:50 -04:00
parent 2f492d9ed1
commit b12f1cc2f1
11 changed files with 72 additions and 54 deletions

View File

@@ -149,7 +149,8 @@ public class DependencyManifestBuilder(DirectoryInfo cacheDirectory, PackageSour
];
}
var client = await packageSources.GetClientAsync(entry.Id);
//don't call this method if client is null
var client = await packageSources.GetClientAsync(entry.Id)!;
dir.Create();

View File

@@ -97,25 +97,43 @@ public class NuGetClient
return _client.GetFromJsonAsync<SearchResult>(builder.Uri, SerializerOptions)!;
}
public static async Task<NuGetClient> CreateFromIndexUrlAsync(string indexUrl)
public static async Task<NuGetClient?> CreateFromIndexUrlAsync(string indexUrl)
{
var client = new HttpClient(new HttpClientHandler
{
AutomaticDecompression = DecompressionMethods.All
AutomaticDecompression = DecompressionMethods.All,
});
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
NuGetClient? ngClient = null;
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
const int MaxRetries = 10;
return new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
for (var i = 0; i < MaxRetries; i++)
{
try
{
var index = await client.GetFromJsonAsync<NuGetIndex>(indexUrl, SerializerOptions);
var (packageBaseAddress, _, _) = index!.Resources.First(b => b.Type.Id == "PackageBaseAddress");
var (registration, _, _) = index.Resources.First(b => b.Type.Id == "RegistrationsBaseUrl");
var (search, _, _) = index.Resources.First(b => b.Type.Id == "SearchQueryService");
if (!packageBaseAddress.EndsWith('/'))
packageBaseAddress += '/';
if (!registration.EndsWith('/'))
registration += '/';
ngClient = new NuGetClient(new Uri(indexUrl), client, new Uri(packageBaseAddress), new Uri(registration), new Uri(search));
break;
}
catch (HttpRequestException ex)
{
Console.WriteLine(ex.Message);
}
}
return ngClient;
}
public override string ToString() => _index.ToString();

View File

@@ -7,19 +7,19 @@ namespace NuGet;
public class PackageSourceMapping(ImmutableArray<PackageSource> sources)
{
private readonly ImmutableArray<(string pattern, Task<NuGetClient> client)> _clients = [
private readonly ImmutableArray<(string pattern, Task<NuGetClient?> client)> _clients = [
..sources.Select(b =>
(b.Pattern,
NuGetClient.CreateFromIndexUrlAsync(b.Url)))
];
public Task<NuGetClient> GetClientAsync(string packageId) =>
public Task<NuGetClient?> GetClientAsync(string packageId) =>
_clients.FirstOrDefault(b => Regex.IsMatch(packageId, b.pattern)).client;
public ConfiguredCancelableAsyncEnumerable<NuGetClient>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
public ConfiguredCancelableAsyncEnumerable<NuGetClient?>.Enumerator GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return _clients.ToAsyncEnumerable()
.SelectAwait(b => new ValueTask<NuGetClient>(b.client))
.SelectAwait(b => new ValueTask<NuGetClient?>(b.client))
.WithCancellation(cancellationToken)
.GetAsyncEnumerator();
}