private async Task Process(PurchaseOrder purchaseOrder) { try { var orderResponse = await _orderClient.GetOrderAsync(purchaseOrder.TrackingNumber); var order = orderResponse.Value; if (order == null) { var tasks = _omniumService.TransferOrderToOmnium(purchaseOrder); var responses = await Task.WhenAll(tasks); var failed = responses.FirstOrDefault(x => !x.IsSuccess()); if (failed != null) { throw new Exception($"Error while adding '{purchaseOrder.TrackingNumber}' to Omnium", failed.OriginalException); } } purchaseOrder[OrderConstants.MetaFieldOmniumSynchronized] = true; purchaseOrder[OrderConstants.MetaFieldOmniumSynchronizedDate] = DateTime.UtcNow; _orderRepository.Save(purchaseOrder); _processed++; } catch (Exception ex) { Logger.Error(ex.Message, ex); _errors++; } }