public static async Task Run(
     [QueueTrigger(QueueNames.BuildProjections)] GenerateAccountProjectionCommand message,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     await FunctionRunner.Run <GenerateProjectionsFunction>(writer, executionContext, async (container, logger) =>
     {
         logger.Debug("Resolving BuildAccountProjectionHandler from container.");
         var handler = container.GetInstance <BuildAccountProjectionHandler>();
         if (handler == null)
         {
             throw new InvalidOperationException("Failed to resolve BuildAccountProjectionHandler from container.");
         }
         await handler.Handle(message);
         logger.Info($"Finished building the account projection for employer: {message.EmployerAccountId}");
     });
 }
示例#2
0
 public static async Task <GenerateAccountProjectionCommand> Run(
     [QueueTrigger(QueueNames.GetAccountBalance)] GenerateAccountProjectionCommand message,
     ExecutionContext executionContext,
     TraceWriter writer)
 {
     return(await FunctionRunner.Run <GetAccountBalanceFunction, GenerateAccountProjectionCommand>(writer, executionContext, async (container, logger) =>
     {
         logger.Debug("Resolving GetAccountBalanceHandler from container.");
         var handler = container.GetInstance <GetAccountBalanceHandler>();
         if (handler == null)
         {
             throw new InvalidOperationException("Failed to resolve GetAccountBalanceHandler from container.");
         }
         await handler.Handle(message);
         logger.Info($"Finished generating the account projection in response to payment run: {message.EmployerAccountId}");
         return message;
     }));
 }
        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}");
        }
        public async Task Handle(GenerateAccountProjectionCommand message)
        {
            _telemetry.AddEmployerAccountId(message.EmployerAccountId);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var projections = await _accountProjectionRepository.InitialiseProjection(message.EmployerAccountId);

            var startDate = new DateTime(
                GetValue(message.StartPeriod?.Year, DateTime.Today.Year),
                GetValue(message.StartPeriod?.Month, DateTime.Today.Month),
                GetValue(message.StartPeriod?.Day, DateTime.Today.Day));

            var messageProjectionSource = await _accountProjectionService.GetOriginalProjectionSource(message.EmployerAccountId, message.ProjectionSource);

            if (messageProjectionSource == ProjectionSource.LevyDeclaration)
            {
                projections.BuildLevyTriggeredProjections(startDate, _config.NumberOfMonthsToProject);
            }
            else
            {
                projections.BuildPayrollPeriodEndTriggeredProjections(startDate, _config.NumberOfMonthsToProject);
            }

            var expiringFunds = await _expiredFundsService.GetExpiringFunds(projections.Projections, message.EmployerAccountId, messageProjectionSource, startDate);

            if (expiringFunds.Any())
            {
                projections.UpdateProjectionsWithExpiredFunds(expiringFunds);
            }

            await _accountProjectionRepository.Store(projections);

            stopwatch.Stop();
            _telemetry.TrackDuration("BuildAccountProjection", stopwatch.Elapsed);
        }
 public static GenerateAccountProjectionCommand Run(
     [QueueTrigger(QueueNames.GenerateProjections)] GenerateAccountProjectionCommand message,
     TraceWriter writer)
 {
     return(message);
 }