Esempio n. 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);
        }
Esempio n. 2
0
 internal ArchiveOperation ToArchiveOperation()
 {
     return(new ArchiveOperation
     {
         ArchiveType = ArchiveType,
         GroupName = GroupName,
         Id = ArchiveOperation.MakeId(RequestId, ArchiveType),
         NumberOfMessagesArchived = NumberOfMessagesArchived,
         RequestId = RequestId,
         Started = Started,
         TotalNumberOfMessages = TotalNumberOfMessages,
         NumberOfBatches = NumberOfBatches,
         CurrentBatch = CurrentBatch
     });
 }
        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);
        }
 public Task <ArchiveOperation> LoadArchiveOperation(IAsyncDocumentSession session, string groupId, ArchiveType archiveType)
 {
     return(session.LoadAsync <ArchiveOperation>(ArchiveOperation.MakeId(groupId, archiveType)));
 }
Esempio n. 5
0
 public ArchiveOperation LoadArchiveOperation(IDocumentSession session, string groupId, ArchiveType archiveType)
 {
     return(session.Load <ArchiveOperation>(ArchiveOperation.MakeId(groupId, archiveType)));
 }