private async Task LoanWorker(ILoanRepository repository, CancellationToken cancellationToken) { try{ var loans = await repository.GetActiveLoan(cancellationToken); foreach (var loan in loans) { if (cancellationToken.IsCancellationRequested) { return; } try{ _logger.LogInformation($"LoanWorker: Start process loan: {loan.Id}"); await _loanProcessor.Process(loan, cancellationToken); await repository.Save(loan, cancellationToken); _logger.LogInformation($"LoanWorker: End process loan: {loan.Id}"); } catch (Exception e) { _logger.LogError(e, $"LoanWorker: {e.Message}"); } } } catch (Exception e) { _logger.LogError(e, $"LoanWorker: {e.Message}"); } }