public async Task Handle(PaymentCreatedMessage message, string allowProjectionsEndpoint)
        {
            if (message.EarningDetails == null)
            {
                throw new InvalidOperationException($"Invalid payment created message. Earning details is null so cannot create commitment data. Employer account: {message.EmployerAccountId}, payment id: {message.Id}");
            }

            _telemetry.AddEmployerAccountId(message.EmployerAccountId);
            _telemetry.AddProperty("Payment Id", message.Id);
            _telemetry.AddProperty("Apprenticeship Id", message.ApprenticeshipId.ToString());
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var commitment = await _repository.Get(message.EmployerAccountId, message.ApprenticeshipId);

            var commitmentModel = _paymentMapper.MapToCommitment(message);

            if (!commitment.RegisterCommitment(commitmentModel))
            {
                _logger.Info($"Not storing the employer commitment. Employer: {message.EmployerAccountId}, ApprenticeshipId: {message.ApprenticeshipId}, payment id: {message.Id}");
                return;
            }

            _logger.Info($"Now storing the employer commitment. Employer: {message.EmployerAccountId}, ApprenticeshipId: {message.ApprenticeshipId}, payment id: {message.Id}");
            await _repository.Store(commitment);

            _logger.Info($"Finished adding the employer commitment. Employer: {message.EmployerAccountId}, ApprenticeshipId: {message.ApprenticeshipId}, payment id: {message.Id}");
            _queueService.SendMessageWithVisibilityDelay(message, allowProjectionsEndpoint);
            stopwatch.Stop();

            _telemetry.TrackDuration("Stored Commitment", stopwatch.Elapsed);
        }
        public async Task Handle(PaymentCreatedMessage paymentCreatedMessage, string allowProjectionsEndpoint)
        {
            _telemetry.AddEmployerAccountId(paymentCreatedMessage.EmployerAccountId);
            _telemetry.AddProperty("Payment Id", paymentCreatedMessage.Id);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var employerPayment = _mapper.MapToPayment(paymentCreatedMessage);

            _logger.Debug($"Now storing the employer payment. Employer: {employerPayment.EmployerAccountId}, Payment Id: {employerPayment.ExternalPaymentId}, Collection period: {employerPayment.CollectionPeriod.Year} - {employerPayment.CollectionPeriod.Month}, Delivery period: {employerPayment.DeliveryPeriod.Year} - {employerPayment.DeliveryPeriod.Month}");
            var payment = await _repository.Get(paymentCreatedMessage.EmployerAccountId, paymentCreatedMessage.Id);

            payment.RegisterPayment(employerPayment);
            await _repository.StorePayment(payment);

            _logger.Info($"Finished adding the employer payment. Employer: {employerPayment.EmployerAccountId}, Payment Id: {employerPayment.ExternalPaymentId}, Collection period: {employerPayment.CollectionPeriod.Year} - {employerPayment.CollectionPeriod.Month}, Delivery period: {employerPayment.DeliveryPeriod.Year} - {employerPayment.DeliveryPeriod.Month}");

            stopwatch.Stop();
            _telemetry.TrackDuration("Store Payment", stopwatch.Elapsed);
            _telemetry.TrackEvent("Stored Payment");
        }
 public static void AddContextInfo(this ITelemetry telemetry, long jobId, long ukprn, string learnerReference)
 {
     AddContextInfo(telemetry, jobId, ukprn);
     telemetry.AddProperty("Learner Reference", learnerReference);
 }
 public static void AddContextInfo(this ITelemetry telemetry, long jobId, long ukprn)
 {
     AddContextInfo(telemetry, jobId);
     telemetry.AddProperty("Ukprn", ukprn.ToString());
 }
 public static void AddContextInfo(this ITelemetry telemetry, long jobId)
 {
     telemetry.AddProperty("Job Id", jobId.ToString());
 }
Exemple #6
0
 public static void AddEmployerAccountId(this ITelemetry telemetry, long employerAccountId)
 {
     telemetry.AddProperty("Employer Account Id", employerAccountId.ToString());
 }