Ejemplo n.º 1
0
        private IndexingPerformanceStats HandleIndexingFor(IndexingBatchForIndex batchForIndex, Etag lastEtag, DateTime lastModified, CancellationToken token)
        {
            currentlyProcessedIndexes.TryAdd(batchForIndex.IndexId, batchForIndex.Index);

            IndexingPerformanceStats performanceResult = null;

            try
            {
                transactionalStorage.Batch(actions =>
                {
                    performanceResult = IndexDocuments(actions, batchForIndex, token);
                });

                performanceResult.OnCompleted();
            }
            catch (Exception e)
            {
                Log.WarnException("Failed to index " + batchForIndex.Index.PublicName, e);
            }
            finally
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("After indexing {0} documents, the new last etag for is: {1} for {2}",
                              batchForIndex.Batch.Docs.Count,
                              lastEtag,
                              batchForIndex.Index.PublicName);
                }

                transactionalStorage.Batch(actions =>
                                           // whatever we succeeded in indexing or not, we have to update this
                                           // because otherwise we keep trying to re-index failed documents
                                           actions.Indexing.UpdateLastIndexed(batchForIndex.IndexId, lastEtag, lastModified));

                Index _;
                currentlyProcessedIndexes.TryRemove(batchForIndex.IndexId, out _);
            }

            return(performanceResult);
        }