Exemplo n.º 1
0
        private async Task Index <T>(IIndexProvider <T> indexProvider, Action <int> pageProgress, CancellationToken token) where T : class
        {
            var       i              = await indexProvider.StartIndexingFrom;
            const int batchSize      = 8;
            var       iteration      = 1;
            var       shouldContinue = true;

            await indexProvider.Init();

            while (shouldContinue && !token.IsCancellationRequested)
            {
                var(items, couldBeMore) = await indexProvider.GetBatchToIndex(i, batchSize);

                if (items.Any())
                {
                    await _indexingClient.Index(items, indexProvider.IndexName, token);
                }

                i += batchSize;

                if (couldBeMore && pageProgress != null && iteration % 10 == 0)
                {
                    pageProgress(i);
                }
                shouldContinue = couldBeMore;
                iteration++;
            }
        }