Exemplo n.º 1
0
        IList <string[]> GetRequestedBatches(IBulkRetryRequest request, out DateTime latestAttempt)
        {
            var response     = new List <string[]>();
            var currentBatch = new List <string>(BatchSize);

            latestAttempt = DateTime.MinValue;

            using (var session = store.OpenSession())
                using (var stream = request.GetDocuments(session))
                {
                    while (stream.MoveNext())
                    {
                        var current = stream.Current.Document;
                        currentBatch.Add(current.UniqueMessageId);

                        if (currentBatch.Count == BatchSize)
                        {
                            response.Add(currentBatch.ToArray());

                            currentBatch.Clear();
                        }

                        var lastDocumentAttempt = current.ProcessingAttempts.Select(x => x.FailureDetails.TimeOfFailure).Max();
                        if (lastDocumentAttempt > latestAttempt)
                        {
                            latestAttempt = lastDocumentAttempt;
                        }
                    }

                    if (currentBatch.Any())
                    {
                        response.Add(currentBatch.ToArray());
                    }
                }

            return(response);
        }
Exemplo n.º 2
0
        async Task <Tuple <List <string[]>, DateTime> > GetRequestedBatches(IBulkRetryRequest request)
        {
            var response      = new List <string[]>();
            var currentBatch  = new List <string>(BatchSize);
            var latestAttempt = DateTime.MinValue;

            using (var session = store.OpenAsyncSession())
                using (var stream = await request.GetDocuments(session).ConfigureAwait(false))
                {
                    while (await stream.MoveNextAsync().ConfigureAwait(false))
                    {
                        var current = stream.Current.Document;
                        currentBatch.Add(current.UniqueMessageId);

                        if (currentBatch.Count == BatchSize)
                        {
                            response.Add(currentBatch.ToArray());

                            currentBatch.Clear();
                        }

                        var lastDocumentAttempt = current.ProcessingAttempts.Select(x => x.FailureDetails.TimeOfFailure).Max();
                        if (lastDocumentAttempt > latestAttempt)
                        {
                            latestAttempt = lastDocumentAttempt;
                        }
                    }

                    if (currentBatch.Any())
                    {
                        response.Add(currentBatch.ToArray());
                    }
                }

            return(Tuple.Create(response, latestAttempt));
        }
        async Task <Tuple <List <string[]>, DateTime> > GetRequestedBatches(IBulkRetryRequest request)
        {
            var response      = new List <string[]>();
            var currentBatch  = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            var latestAttempt = DateTime.MinValue;

            using (var session = store.OpenAsyncSession())
                using (var stream = await request.GetDocuments(session).ConfigureAwait(false))
                {
                    while (await stream.MoveNextAsync().ConfigureAwait(false))
                    {
                        var current = stream.Current.Document;
                        currentBatch.Add(current.UniqueMessageId);

                        if (currentBatch.Count == BatchSize)
                        {
                            response.Add(currentBatch.ToArray());

                            currentBatch.Clear();
                        }

                        var lastDocumentAttempt = current.LatestTimeOfFailure;
                        if (lastDocumentAttempt > latestAttempt)
                        {
                            latestAttempt = lastDocumentAttempt;
                        }
                    }

                    if (currentBatch.Count > 0)
                    {
                        response.Add(currentBatch.ToArray());
                    }
                }

            return(Tuple.Create(response, latestAttempt));
        }