示例#1
0
        public static async Task RunAsync(
            [QueueTrigger(Constants.IndexingQueue, Connection = Constants.IndexingQueueConnection)] PackageOperation packageOperation,
            [Blob("index/{Id}.{VersionNormalized}.json", FileAccess.ReadWrite, Connection = Constants.IndexConnection)] CloudBlockBlob packageBlob,
            ILogger log)
        {
            var indexClient  = SearchServiceClient.Indexes.GetClient(Constants.SearchServiceIndexName);
            var indexActions = new List <IndexAction <PackageDocument> >();

            // Build actions
            if (packageOperation.IsAdd())
            {
                await RunAddPackageAsync(packageOperation, packageBlob, log, indexActions);
            }
            else if (packageOperation.IsDelete())
            {
                await RunDeletePackageAsync(packageOperation, packageBlob, indexClient, indexActions);
            }

            // Commit changes to index
            if (!Constants.DevCommitToSearchIndex)
            {
                return;
            }

            log.LogInformation("Committing changes for package {packageId}@{packageVersionNormalized} to index...", packageOperation.Id, packageOperation.Version);
            foreach (var actions in indexActions.Paged(BatchCommitSize))
            {
                var indexBatch = IndexBatch.New(actions);
                try
                {
                    log.LogInformation("Committing batch to index...");
                    await indexClient.Documents.IndexAsync(indexBatch);

                    log.LogInformation("Committed batch to index.");
                }
                catch (IndexBatchException ex)
                {
                    log.LogError("Error while committing batch to index.", ex);
                    foreach (var result in ex.IndexingResults)
                    {
                        if (result.Succeeded)
                        {
                            continue;
                        }

                        log.LogError("Result for {key}: {message}", result.Key, result.ErrorMessage);
                    }
                    throw;
                }
            }
            log.LogInformation("Finished committing changes for package {packageId}@{packageVersionNormalized} to index.", packageOperation.Id, packageOperation.Version);
        }
 public static async Task RunAsync(
     [QueueTrigger(Constants.DownloadingQueue, Connection = Constants.DownloadingQueueConnection)] PackageOperation packageOperation,
     [Blob("packages/{Id}/{VersionNormalized}/{Id}.{VersionNormalized}.nupkg", FileAccess.ReadWrite, Connection = Constants.DownloadsConnection)] CloudBlockBlob packageBlob,
     ILogger log)
 {
     if (packageOperation.IsAdd())
     {
         await RunAddPackageAsync(packageOperation, packageBlob, log);
     }
     else if (packageOperation.IsDelete())
     {
         await RunDeletePackageAsync(packageOperation, packageBlob, log);
     }
 }
示例#3
0
        public static async Task RunAsync(
            [QueueTrigger(Constants.IndexingQueue, Connection = Constants.IndexingQueueConnection)]
            PackageOperation packageOperation,

            [AzureSearchIndex(
                 SearchServiceName = Constants.SearchServiceName,
                 SearchServiceKey = Constants.SearchServiceKey,
                 IndexName = Constants.SearchServiceIndexName,
                 IndexDocumentType = typeof(PackageDocument),
                 IndexAction = IndexAction.MergeOrUpload,
                 CreateOrUpdateIndex = true)]
            IAsyncCollector <PackageDocument> documentAddCollector,

            [AzureSearchIndex(
                 SearchServiceName = Constants.SearchServiceName,
                 SearchServiceKey = Constants.SearchServiceKey,
                 IndexName = Constants.SearchServiceIndexName,
                 IndexDocumentType = typeof(PackageDocument),
                 IndexAction = IndexAction.Delete,
                 CreateOrUpdateIndex = true)]
            IAsyncCollector <PackageDocument> documentDeleteCollector,

            [Blob("index/{Id}.{VersionNormalized}.json", FileAccess.ReadWrite, Connection = Constants.IndexConnection)]
            CloudBlockBlob packageBlob,

            ILogger log)
        {
            // Build actions
            if (packageOperation.IsAdd())
            {
                await RunAddPackageAsync(packageOperation, packageBlob, log, Constants.DevCommitToSearchIndex
                                         ?documentAddCollector
                                         : DummyAsyncCollector.For <PackageDocument>());
            }
            else if (packageOperation.IsDelete())
            {
                await RunDeletePackageAsync(packageOperation, packageBlob, Constants.DevCommitToSearchIndex
                                            ?documentDeleteCollector
                                            : DummyAsyncCollector.For <PackageDocument>());
            }
        }
        public static async Task RunAsync(
            [NuGetCatalogTrigger(CursorBlobName = "catalogCursor.json", UseBatchProcessor = true)] PackageOperation packageOperation,
            [Queue(Constants.IndexingQueue, Connection = Constants.IndexingQueueConnection)] ICollector <PackageOperation> indexingQueueCollector,
            [Queue(Constants.DownloadingQueue, Connection = Constants.DownloadingQueueConnection)] ICollector <PackageOperation> downloadingQueueCollector,
            [Table("packages")] CloudTable outputTable,
            ILogger log)
        {
            // Log
            log.LogInformation("Appending package {action} operation for {packageId}@{packageVersionNormalized}...", packageOperation.Action, packageOperation.Id, packageOperation.Version);

            // Append to queues
            indexingQueueCollector.Add(packageOperation);
            downloadingQueueCollector.Add(packageOperation);

            // Store (or delete) from table
            var entity = new PackageEntity
            {
                Id                = packageOperation.Id,
                Version           = packageOperation.Version,
                VersionVerbatim   = packageOperation.VersionVerbatim,
                VersionNormalized = packageOperation.VersionNormalized,
                Published         = packageOperation.Published,
                Url               = packageOperation.PackageUrl,
                IsListed          = packageOperation.IsListed,
                Timestamp         = DateTimeOffset.UtcNow
            };

            if (packageOperation.IsAdd())
            {
                await outputTable.ExecuteAsync(TableOperation.InsertOrMerge(entity));
            }
            else
            {
                await outputTable.ExecuteAsync(TableOperation.Delete(entity));
            }

            log.LogInformation("Finished appending package {action} operation for {packageId}@{packageVersionNormalized}.", packageOperation.Action, packageOperation.Id, packageOperation.Version);
        }