예제 #1
0
        private async Task ProcessFiles()
        {
            try
            {
                var files = this.ReadFiles();

                if (files.Count() > 0)
                {
                    _logger.LogInformation($"{files.Count()} file(s) were found. Starting to process them.");

                    foreach (var file in files)
                    {
                        try
                        {
                            var workflow = WorkflowFactory.GetWorkflow(file);

                            workflow.Execute();

                            file.MoveTo($"{this.DATA_PATH}\\success\\{file.Name}", true);

                            _logger.LogInformation($"{file} processed successfully.");
                        }
                        catch (Exception ex) // An exception here should not stop the background process from running

                        {
                            var path = $"{file.DirectoryName}\\error\\{file.Name}.error";
                            file.MoveTo(path, true);
                            _logger.LogError(ex, $"An error occured while processing {file.Name}");
                        }

                        await Task.Delay(this.throttleRate);
                    }

                    _logger.LogInformation($"Finished processing all files");
                }
                else
                {
                    _logger.LogInformation($"There are no files to be processed");
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical($"A fatal exception occurred: {ex.Message}");
            }
        }