public async Task Run(CancellationTokenSource tokenSource) { var token = tokenSource.Token; var succeeded = 0; var failed = 0; using (var session = store.OpenAsyncSession()) { var query = session.Query <FailedErrorImport, FailedErrorImportIndex>(); using (var ie = await session.Advanced.StreamAsync(query, token) .ConfigureAwait(false)) { while (!token.IsCancellationRequested && await ie.MoveNextAsync().ConfigureAwait(false)) { FailedTransportMessage dto = ((dynamic)ie.Current.Document).Message; try { var messageContext = new MessageContext(dto.Id, dto.Headers, dto.Body, EmptyTransaction, EmptyTokenSource, EmptyContextBag); await errorIngestor.Ingest(messageContext).ConfigureAwait(false); await store.AsyncDatabaseCommands.DeleteAsync(ie.Current.Key, null, token) .ConfigureAwait(false); succeeded++; if (Logger.IsDebugEnabled) { Logger.Debug($"Successfully re-imported failed error message {dto.Id}."); } } catch (OperationCanceledException) { // no-op } catch (Exception e) { Logger.Error($"Error while attempting to re-import failed error message {dto.Id}.", e); failed++; } } } } Logger.Info($"Done re-importing failed errors. Successfully re-imported {succeeded} messages. Failed re-importing {failed} messages."); if (failed > 0) { Logger.Warn($"{failed} messages could not be re-imported. This could indicate a problem with the data. Contact Particular support if you need help with recovering the messages."); } }
async Task Run <T, I>(CancellationToken token) where I : AbstractIndexCreationTask, new() { var succeeded = 0; var failed = 0; using (var session = store.OpenAsyncSession()) { var query = session.Query <T, I>(); using (var ie = await session.Advanced.StreamAsync(query, token) .ConfigureAwait(false)) { while (!token.IsCancellationRequested && await ie.MoveNextAsync().ConfigureAwait(false)) { FailedTransportMessage dto = ((dynamic)ie.Current.Document).Message; try { var messageContext = new MessageContext(dto.Id, dto.Headers, dto.Body, EmptyTransaction, EmptyTokenSource, EmptyContextBag); var entity = await auditImporter.ConvertToSaveMessage(messageContext) .ConfigureAwait(false); using (var storeSession = store.OpenAsyncSession()) { await storeSession.StoreAsync(entity, token).ConfigureAwait(false); await storeSession.SaveChangesAsync(token).ConfigureAwait(false); } await store.AsyncDatabaseCommands.DeleteAsync(ie.Current.Key, null, token) .ConfigureAwait(false); succeeded++; Logger.Info($"Successfully re-imported failed audit message {dto.Id}."); } catch (Exception e) { Logger.Error($"Error while attempting to re-import failed audit message {dto.Id}.", e); failed++; } } } } Logger.Info($"Done re-importing failed audits. Successfully re-imported {succeeded} messaged. Failed re-importing {failed} messages."); if (failed > 0) { Logger.Warn($"{failed} messages could not be re-imported. This could indicate a problem with the data. Contact Particular support if you need help in recovering the messages."); } }
void Run <T, I>(CancellationToken token) where I : AbstractIndexCreationTask, new() { var succeeded = 0; var failed = 0; using (var session = store.OpenSession()) { var query = session.Query <T, I>(); using (var ie = session.Advanced.Stream(query)) { while (!token.IsCancellationRequested && ie.MoveNext()) { FailedTransportMessage dto = ((dynamic)ie.Current.Document).Message; try { var transportMessage = new TransportMessage(dto.Id, dto.Headers) { Body = dto.Body }; var entity = auditImporter.ConvertToSaveMessage(transportMessage); using (var storeSession = store.OpenSession()) { storeSession.Store(entity); storeSession.SaveChanges(); } store.DatabaseCommands.Delete(ie.Current.Key, null); succeeded++; Logger.Info($"Successfully re-imported failed audit message {dto.Id}."); } catch (Exception e) { Logger.Error($"Error while attempting to re-import failed audit message {dto.Id}.", e); failed++; } } } } Logger.Info($"Done re-importing failed audits. Successfully re-imported {succeeded} messaged. Failed re-importing {failed} messages."); if (failed > 0) { Logger.Warn($"{failed} messages could not be re-imported. This could indicate a problem with the data. Contact Particular support if you need help in recovering the messages."); } }