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); } }
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>()); } }