protected async Task PerformUndo(PublishedFundingUndoJobParameters parameters) { try { IPublishedFundingUndoTaskFactory taskFactory = _factoryLocator.GetTaskFactoryFor(parameters); IPublishedFundingUndoJobTask initialiseContextTask = taskFactory.CreateContextInitialisationTask(); IPublishedFundingUndoJobTask undoPublishedProviderTask = taskFactory.CreatePublishedProviderUndoTask(); IPublishedFundingUndoJobTask undoPublishedProviderVersionTask = taskFactory.CreatePublishedProviderVersionUndoTask(); IPublishedFundingUndoJobTask undoPublishedFundingTask = taskFactory.CreatePublishedFundingUndoTask(); IPublishedFundingUndoJobTask undoPublishedFundingVersionTask = taskFactory.CreatePublishedFundingVersionUndoTask(); PublishedFundingUndoTaskContext taskContext = new PublishedFundingUndoTaskContext(parameters); await initialiseContextTask.Run(taskContext); Task[] undoTasks = new[] { undoPublishedFundingTask.Run(taskContext), undoPublishedFundingVersionTask.Run(taskContext), undoPublishedProviderTask.Run(taskContext), undoPublishedProviderVersionTask.Run(taskContext) }; await TaskHelper.WhenAllAndThrow(undoTasks); EnsureNoTaskErrors(taskContext); } catch (Exception e) { string errorMessage = $"Unable to complete {PublishedFundingUndoJob} for correlationId: {parameters.ForCorrelationId}.\n{e.Message}"; throw new NonRetriableException(errorMessage, e); } }
private void EnsureNoTaskErrors(PublishedFundingUndoTaskContext taskContext) { if (taskContext.Errors.IsNullOrEmpty()) { return; } throw new InvalidOperationException("Undo tasks generated unhandled exceptions", new AggregateException(taskContext.Errors)); }