Пример #1
0
        /// <summary>
        /// Generate index actions for each provided ID. This reads the version list per package ID so we want to
        /// parallel this work by <see cref="AzureSearchJobConfiguration.MaxConcurrentVersionListWriters"/>.
        /// </summary>
        private async Task GenerateIndexActionsAsync(
            ConcurrentBag <string> idsToIndex,
            ConcurrentBag <IdAndValue <IndexActions> > indexActionsToPush,
            SortedDictionary <string, long> changes)
        {
            await ParallelAsync.Repeat(
                async() =>
            {
                while (idsToIndex.TryTake(out var id))
                {
                    var indexActions = await _indexActionBuilder.UpdateAsync(
                        id,
                        sf => _searchDocumentBuilder.UpdateDownloadCount(id, sf, changes[id]));

                    if (indexActions.IsEmpty)
                    {
                        continue;
                    }

                    Guard.Assert(indexActions.Hijack.Count == 0, "There should be no hijack index changes.");

                    indexActionsToPush.Add(new IdAndValue <IndexActions>(id, indexActions));
                }
            },
                _options.Value.MaxConcurrentVersionListWriters);
        }
Пример #2
0
        private async Task WorkAsync(ConcurrentBag <IdAndValue <string[]> > changesBag)
        {
            await Task.Yield();

            var batchPusher = _batchPusherFactory();

            while (changesBag.TryTake(out var changes))
            {
                // Note that the owner list passed in can be empty (e.g. if the last owner was deleted or removed from
                // the package registration).
                var indexActions = await _searchIndexActionBuilder.UpdateAsync(
                    changes.Id,
                    searchFilters => _searchDocumentBuilder.UpdateOwners(changes.Id, searchFilters, changes.Value));

                // If no index actions are returned, this means that there are no listed packages or no
                // packages at all.
                if (indexActions.IsEmpty)
                {
                    continue;
                }

                batchPusher.EnqueueIndexActions(changes.Id, indexActions);

                // Note that this method can throw a storage exception if one of the version lists has been modified
                // during the execution of this job loop.
                await batchPusher.PushFullBatchesAsync();
            }

            await batchPusher.FinishAsync();
        }