private async Task ConsumeIndexActionsAsync(
            ChannelReader <IndexAction <KeyedDocument> > channel,
            CancellationToken cancellationToken)
        {
            var actions = new List <IndexAction <KeyedDocument> >();

            while (await channel.WaitToReadAsync(cancellationToken))
            {
                while (channel.TryRead(out var action))
                {
                    actions.Add(action);

                    if (actions.Count >= AzureSearchBatchIndexer.MaxBatchSize)
                    {
                        await _indexer.IndexAsync(actions, cancellationToken);

                        actions.Clear();
                    }
                }
            }

            if (actions.Any())
            {
                await _indexer.IndexAsync(actions, cancellationToken);
            }

            _logger.LogInformation("Finished consuming index actions");
        }
Exemple #2
0
        public async Task BuildAsync(string packageId, CancellationToken cancellationToken = default)
        {
            var packages = await _packages.FindAsync(packageId, includeUnlisted : true);

            if (!packages.Any())
            {
                _logger.LogError("Could not index package {PackageId} because it does not exist", packageId);
                return;
            }

            var packageRegistration = new PackageRegistration(
                packageId,
                packages);

            // Update the package metadata resource.
            _logger.LogInformation(
                "Updating the package metadata resource for {PackageId}...",
                packageId);

            var index = _registrationBuilder.BuildIndex(packageRegistration);

            await UploadRegistrationIndexAsync(packageId, index, cancellationToken);

            // Update the search service.
            _logger.LogInformation(
                "Updating the search service for {PackageId}...",
                packageId);

            var actions = _actionBuilder.UpdatePackage(packageRegistration);

            await _search.IndexAsync(actions, cancellationToken);

            _logger.LogInformation("Indexed package {PackageId}", packageId);
        }