Example #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            using var scope = _service.CreateScope();
            _contextDb      = scope.ServiceProvider.GetService <IContextGateway>();

            //Get docs that can be reprocessed because of an error
            if (_contextDb != null)
            {
                var accumulatedDocs = (await _contextDb.GetPendingDocsAsync()).ToList();
                //Get all files in folder
                var newDocs = _docManager.GetProcessableDocs(_options.SourceDirectory, accumulatedDocs, _options.DocChunk).ToList();
                //Save new docs a DB
                var docs = (await _contextDb.SaveAsync(newDocs)).ToList();
                //Complete the list of processable jobs
                docs.AddRange(accumulatedDocs);

                if (!docs.Any())
                {
                    return;
                }

                //Increment the number of retry
                docs.IncrementNumberOfRetry();

                //validate docs list
                var validDocs = docs
                                .Where(doc => _validator.Validate(doc))
                                .GetValidDestinations(_options.DestinationDirectory)
                                .ToList();

                //Get invalid docs
                var invalidDocs = docs
                                  .Except(validDocs)
                                  .GetInValidDestinations(_options.ErrorsDirectory)
                                  .ToList();

                _logger.LogInformation("Processing valid files.");
                await ProcessDocsAsync(validDocs);

                _logger.LogInformation("Processing invalid files.");
                await ProcessDocsAsync(invalidDocs);
            }
        }
Example #2
0
 public ExcelExportController(IContextGateway context)
 {
     _context = context;
 }