コード例 #1
0
        public ArchiveOperation CreateArchiveOperation(IDocumentSession session, string groupId, ArchiveType archiveType, DateTime?cutOff, int numberOfMessages, string groupName, int batchSize)
        {
            var operation = new ArchiveOperation
            {
                Id                       = ArchiveOperation.MakeId(groupId, archiveType),
                RequestId                = groupId,
                ArchiveType              = archiveType,
                TotalNumberOfMessages    = numberOfMessages,
                NumberOfMessagesArchived = 0,
                Started                  = DateTime.Now,
                GroupName                = groupName,
                NumberOfBatches          = (int)Math.Ceiling(numberOfMessages / (float)batchSize),
                CurrentBatch             = 0
            };

            session.Store(operation);

            int documentCount = 0;
            var indexQuery    = session.Query <FailureGroupMessageView>(new FailedMessages_ByGroup().IndexName);

            if (cutOff.HasValue)
            {
                indexQuery = indexQuery.Customize(x => x.WaitForNonStaleResultsAsOf(cutOff.Value));
            }

            var docQuery = indexQuery
                           .Where(failure => failure.FailureGroupId == groupId)
                           .Where(failure => failure.Status == FailedMessageStatus.Unresolved)
                           .AsProjection <FailureGroupMessageView>()
                           .Select(document => document.Id);

            var docs = StreamResults(session, docQuery).ToArray();

            var batches = docs
                          .GroupBy(d =>
            {
                return(documentCount++ / batchSize);
            });

            foreach (var batch in batches)
            {
                var archiveBatch = new ArchiveBatch
                {
                    Id          = ArchiveBatch.MakeId(groupId, archiveType, batch.Key),
                    DocumentIds = batch.ToList()
                };

                session.Store(archiveBatch);
            }

            return(operation);
        }
コード例 #2
0
        public async Task ArchiveMessageGroupBatch(IAsyncDocumentSession session, ArchiveBatch batch)
        {
            var patchCommands = batch?.DocumentIds.Select(documentId => new PatchCommandData {
                Key = documentId, Patches = patchRequest
            });

            if (patchCommands != null)
            {
                await session.Advanced.DocumentStore.AsyncDatabaseCommands.BatchAsync(patchCommands)
                .ConfigureAwait(false);

                await session.Advanced.DocumentStore.AsyncDatabaseCommands.DeleteAsync(batch.Id, null)
                .ConfigureAwait(false);
            }
        }
コード例 #3
0
        public async Task <ArchiveOperation> CreateArchiveOperation(IAsyncDocumentSession session, string groupId, ArchiveType archiveType, int numberOfMessages, string groupName, int batchSize)
        {
            var operation = new ArchiveOperation
            {
                Id                       = ArchiveOperation.MakeId(groupId, archiveType),
                RequestId                = groupId,
                ArchiveType              = archiveType,
                TotalNumberOfMessages    = numberOfMessages,
                NumberOfMessagesArchived = 0,
                Started                  = DateTime.Now,
                GroupName                = groupName,
                NumberOfBatches          = (int)Math.Ceiling(numberOfMessages / (float)batchSize),
                CurrentBatch             = 0
            };

            await session.StoreAsync(operation).ConfigureAwait(false);

            var documentCount = 0;
            var indexQuery    = session.Query <FailureGroupMessageView>(new FailedMessages_ByGroup().IndexName);

            var docQuery = indexQuery
                           .Where(failure => failure.FailureGroupId == groupId)
                           .Where(failure => failure.Status == FailedMessageStatus.Unresolved)
                           .Select(document => document.Id);

            var docs = await StreamResults(session, docQuery).ConfigureAwait(false);

            var batches = docs
                          .GroupBy(d => documentCount++ / batchSize);

            foreach (var batch in batches)
            {
                var archiveBatch = new ArchiveBatch
                {
                    Id          = ArchiveBatch.MakeId(groupId, archiveType, batch.Key),
                    DocumentIds = batch.ToList()
                };

                await session.StoreAsync(archiveBatch).ConfigureAwait(false);
            }

            return(operation);
        }
コード例 #4
0
        public void ArchiveMessageGroupBatch(IDocumentSession session, ArchiveBatch batch)
        {
            var patchCommands = batch?.DocumentIds
                                .Select(documentId =>
                                        new PatchCommandData
            {
                Key     = documentId,
                Patches = new[]
                {
                    new PatchRequest
                    {
                        Type  = PatchCommandType.Set,
                        Name  = "Status",
                        Value = (int)FailedMessageStatus.Archived
                    }
                }
            });

            if (patchCommands != null)
            {
                session.Advanced.DocumentStore.DatabaseCommands.Batch(patchCommands);
                session.Advanced.DocumentStore.DatabaseCommands.Delete(batch.Id, null);
            }
        }