예제 #1
0
        private static async Task <NuGetPackage> GetPackage(NuGetV2Feed feed, Uri url, bool includeDownloadUrl)
        {
            var packages = await feed.GetPackagesAsync(
                url,
                includeDownloadUrl,
                continuationsToFollow : 0);

            return(packages.FirstOrDefault());
        }
예제 #2
0
파일: Job.cs 프로젝트: edyoung/NuGet.Jobs
        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?
        }