private async Task ProcessFile(string fiteItem) { //Move the file from Src folder to Processing folder var file = _jobStorage.MoveFileToProcessing(fiteItem); try { //Parse and serialize csv file var productsList = _productsCsvParser.ParseInBatches(file, batchSize: 5000); //insert in database foreach (var products in productsList) { await _productService.Insert(products.ToList()); } //remove file from processing string filename = file.Substring(file.LastIndexOf("\\") + 1); _jobStorage.RemoveFileFromProcessing(filename); } catch (Exception) { //move to failed folder to be picked up later string filename = file.Substring(file.LastIndexOf("\\") + 1); _jobStorage.MoveFileToFailed(filename); } }
public async Task Handle(FileUploadedEvent notification, CancellationToken cancellationToken) { _logger.LogInformation("Db Transformer started."); //Move the file from Src folder to Processing folder var file = _jobStorage.MoveFileToProcessing(notification.FileName); _logger.LogInformation($"Db Transformer Processing {file}"); try { //Parse and serialize csv file var productsList = _productsCsvParser.ParseInBatches(file, batchSize: 1000); //insert in database foreach (var products in productsList) { await _productService.Insert(products.ToList()); } //remove file from processing string filename = file.Substring(file.LastIndexOf("\\") + 1); _jobStorage.RemoveFileFromProcessing(filename); } catch (Exception e) { _logger.LogError($"Failed processing {file} , moving file to failed folder", e); string filename = file.Substring(file.LastIndexOf("\\") + 1); _jobStorage.MoveFileToFailed(filename); } }