protected override async Task RunInternalAsync(CancellationToken cancellationToken) { var currentMessageCount = await _queue.GetMessageCount(cancellationToken); if (currentMessageCount > _maxRequeueQueueSize) { Logger.LogInformation( "Can't requeue any invalid packages because the queue has too many messages ({CurrentMessageCount} > {MaxRequeueQueueSize})!", currentMessageCount, _maxRequeueQueueSize); return; } var invalidPackages = await _statusService.GetAsync(PackageState.Invalid, cancellationToken); await Task.WhenAll(invalidPackages.Select(invalidPackage => { try { Logger.LogInformation("Requeuing invalid package {PackageId} {PackageVersion}.", invalidPackage.Package.Id, invalidPackage.Package.Version); return(_queue.AddAsync( new PackageValidatorContext(invalidPackage), cancellationToken)); } catch (Exception e) { Logger.LogError("Failed to requeue invalid package {PackageId} {PackageVersion}: {Exception}", invalidPackage.Package.Id, invalidPackage.Package.Version, e); return(Task.FromResult(0)); } })); }
private async Task EnqueueAsync(ConcurrentBag <CatalogCommitItem> itemBag, CancellationToken cancellationToken) { while (itemBag.TryTake(out var item)) { if (!item.TypeUris.Any(itemType => itemType.AbsoluteUri != Schema.DataTypes.PackageDetails.AbsoluteUri)) { continue; } var id = item.PackageIdentity.Id.ToLowerInvariant(); var version = item.PackageIdentity.Version.ToNormalizedString().ToLowerInvariant(); await _queue.AddAsync(new PackageMessage(id, version), cancellationToken); } }
private async Task EnqueueAsync(ConcurrentBag <JToken> itemBag, CancellationToken cancellationToken) { while (itemBag.TryTake(out var item)) { var id = item["nuget:id"].ToString().ToLowerInvariant(); var version = NuGetVersionUtility.NormalizeVersion(item["nuget:version"].ToString().ToLowerInvariant()); var type = item["@type"].ToString().Replace("nuget:", Schema.Prefixes.NuGet); if (type != Schema.DataTypes.PackageDetails.ToString()) { continue; } await _queue.AddAsync(new PackageMessage(id, version), cancellationToken); } }
protected override async Task ProcessSortedBatchAsync(CollectorHttpClient client, KeyValuePair <FeedPackageIdentity, IList <JObject> > sortedBatch, JToken context, CancellationToken cancellationToken) { var packageId = sortedBatch.Key.Id; var packageVersion = sortedBatch.Key.Version; var feedPackage = new FeedPackageIdentity(packageId, packageVersion); _logger.LogInformation("Processing catalog entries for {PackageId} {PackageVersion}.", packageId, packageVersion); var catalogEntries = sortedBatch.Value.Select(c => new CatalogIndexEntry(c)); _logger.LogInformation("Adding {MostRecentCatalogEntryUri} to queue.", catalogEntries.OrderByDescending(c => c.CommitTimeStamp).First().Uri); await _queue.AddAsync( new PackageValidatorContext(feedPackage, catalogEntries), cancellationToken); }
private async Task ProcessPackagesAsync( ConcurrentBag <PackageStatusOutdatedCheck> checkBag, CancellationToken cancellationToken) { while (checkBag.TryTake(out var check)) { if (await IsStatusOutdatedAsync(check, cancellationToken)) { Logger.LogWarning("Status for {Id} {Version} is outdated!", check.Identity.Id, check.Identity.Version); var context = new PackageValidatorContext(check.Identity, null); await _packageValidatorContextQueue.AddAsync(context, cancellationToken); } else { Logger.LogInformation("Status for {Id} {Version} is up to date.", check.Identity.Id, check.Identity.Version); } } }
public Task AddAsync(T contents, CancellationToken token) { return(_queue.AddAsync(_messageSerializer.Serialize(contents), token)); }