public async Task <bool> Run() { _logger.LogInformation($"Creating rescan request for {{{TraceConstant.PackageId}}} " + $"{{{TraceConstant.PackageVersion}}}", PackageId, PackageVersion); var package = await Util.GetPackage( _galleryBaseAddress, _feed, PackageId, PackageVersion, includeDownloadUrl : false); if (package == null) { _logger.LogError($"Unable to find {{{TraceConstant.PackageId}}} " + $"{{{TraceConstant.PackageVersion}}}. Terminating.", PackageId, PackageVersion); return(false); } _logger.LogInformation($"Found package {{{TraceConstant.PackageId}}} " + $"{{{TraceConstant.PackageVersion}}}", package.Id, package.Version); _logger.LogInformation($"Submitting rescan request for {{{TraceConstant.PackageId}}} " + $"{{{TraceConstant.PackageVersion}}}", package.Id, package.Version); await _packageValidationService.StartValidationProcessAsync(package, new[] { VcsValidator.ValidatorName }); _logger.LogInformation($"Done submitting rescan request for {{{TraceConstant.PackageId}}} " + $"{{{TraceConstant.PackageVersion}}}", package.Id, package.Version); return(true); }
private async Task RunOrchestrateAsync() { Logger.LogInformation($"{{{TraceConstant.EventName}}}: Attempting orchestration", "OrchestrationAttempt"); // Retrieve cursor (last created / last edited) var cursor = new PackageValidationOrchestrationCursor(_cloudStorageAccount, _containerName + "-audit", "cursor.json", LoggerFactory); await cursor.LoadAsync(); // Setup package validation service var packageValidationService = new PackageValidationService(_cloudStorageAccount, _containerName, LoggerFactory); // Get reference timestamps var referenceLastCreated = cursor.LastCreated ?? DateTimeOffset.UtcNow.AddMinutes(-15); var referenceLastEdited = cursor.LastEdited ?? DateTimeOffset.UtcNow.AddMinutes(-15); // Fetch newly added / edited packages and enqueue validations using (var client = new HttpClient()) { var packages = new HashSet <NuGetPackage>(new NuGetV2PackageEqualityComparer()); var feed = new NuGetV2Feed(client, LoggerFactory.CreateLogger <NuGetV2Feed>()); var createdPackagesUrl = MakePackageQueryUrl(_galleryBaseAddress, "Created", referenceLastCreated); Logger.LogInformation("Querying packages created since {StartTime}, URL: {QueryUrl}", referenceLastCreated, createdPackagesUrl); var createdPackages = await feed.GetPackagesAsync( createdPackagesUrl, includeDownloadUrl : false, continuationsToFollow : 0); foreach (var package in createdPackages) { packages.Add(package); if (package.Created > cursor.LastCreated || cursor.LastCreated == null) { cursor.LastCreated = package.Created; } } // todo: do we also want to check edited packages again? //var editedPackagesUrl = MakePackageQueryUrl(_galleryBaseAddress, "LastEdited", referenceLastEdited); //var editedPackages = await feed.GetPackagesAsync(editedPackagesUrl, followContinuations: true); //foreach (var package in editedPackages) //{ // //packages.Add(package); // if (package.LastEdited > cursor.LastEdited || cursor.LastEdited == null) // { // cursor.LastEdited = package.LastEdited; // } //} // Start the validation process for each package foreach (var package in packages) { await packageValidationService.StartValidationProcessAsync(package, _requestValidationTasks); } // Store cursor await cursor.SaveAsync(); } // TODO: check for validations that have never been executed? }