public async Task RefreshCurrentBalance(long accountId) { var currentBalance = await _currentBalanceRepository.Get(accountId); if (!await currentBalance.RefreshBalance()) { return; } await _currentBalanceRepository.Store(currentBalance); }
public async Task Handle(GenerateAccountProjectionCommand message) { _logger.Debug($"Getting balances for account: {message.EmployerAccountId}"); _telemetry.AddEmployerAccountId(message.EmployerAccountId); var currentBalance = await _currentBalanceRepository.Get(message.EmployerAccountId); var refreshBalance = await _accountProjectionService.GetOriginalProjectionSource(message.EmployerAccountId, message.ProjectionSource) == ProjectionSource.PaymentPeriodEnd ? currentBalance.RefreshBalance(true, true) : currentBalance.RefreshBalance(true); if (!await refreshBalance) { _telemetry.TrackEvent("Account Balance Already Refreshed"); _logger.Warn($"Failed to refresh the account balance for account {message.EmployerAccountId}. It's possible the account has been refreshed recently."); return; } await _currentBalanceRepository.Store(currentBalance); _telemetry.TrackEvent("Refreshed Account Balance"); _logger.Info($"Finished updating recorded balance for account: {message.EmployerAccountId}"); }