public async Task Stores_Earning_Job_Inprogress_Messages()
        {
            var generatedMessageA = new GeneratedMessage
            {
                StartTime   = DateTimeOffset.UtcNow,
                MessageId   = Guid.NewGuid(),
                MessageName = "MessageA",
            };
            var generatedMessageB = new GeneratedMessage
            {
                StartTime   = DateTimeOffset.UtcNow,
                MessageId   = Guid.NewGuid(),
                MessageName = "MessageB",
            };
            var jobStarted = new RecordEarningsJobAdditionalMessages
            {
                GeneratedMessages = new List <GeneratedMessage> {
                    generatedMessageA, generatedMessageB
                },
                JobId = 1,
            };

            var service = mocker.Create <EarningsJobService>();
            await service.RecordNewJobAdditionalMessages(jobStarted, CancellationToken.None);

            mocker.Mock <IJobStorageService>()
            .Verify(x => x.StoreInProgressMessages(It.Is <long>(jobId => jobId == jobStarted.JobId), It.Is <List <InProgressMessage> >(identifiers =>
                                                                                                                                       identifiers.Count == 2 &&
                                                                                                                                       identifiers.Exists(inProgress => inProgress.MessageId == generatedMessageA.MessageId) &&
                                                                                                                                       identifiers.Exists(inProgress => inProgress.MessageId == generatedMessageB.MessageId)), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task StartJob(long jobId, long ukprn, DateTime ilrSubmissionTime, short collectionYear, byte collectionPeriod, List <GeneratedMessage> generatedMessages, DateTimeOffset startTime)
        {
            logger.LogVerbose($"Sending request to record start of earnings job. Job Id: {jobId}, Ukprn: {ukprn}");
            try
            {
                var batchSize = 1000; //TODO: this should come from config
                List <GeneratedMessage> batch;
                var providerEarningsEvent = new RecordEarningsJob
                {
                    StartTime         = startTime,
                    JobId             = jobId,
                    Ukprn             = ukprn,
                    IlrSubmissionTime = ilrSubmissionTime,
                    CollectionYear    = collectionYear,
                    CollectionPeriod  = collectionPeriod,
                    GeneratedMessages = generatedMessages.Take(batchSize).ToList(),
                    LearnerCount      = generatedMessages.Count
                };

                var jobsEndpointName        = config.GetSettingOrDefault("Monitoring_JobsService_EndpointName", "sfa-das-payments-monitoring-jobs");
                var partitionedEndpointName = $"{jobsEndpointName}{partitionName.PartitionNameForJob(jobId, ukprn)}";
                logger.LogVerbose($"Endpoint for RecordEarningsJob for Job Id {jobId} is `{partitionedEndpointName}`");
                await messageSession.Send(partitionedEndpointName, providerEarningsEvent).ConfigureAwait(false);

                var skip = batchSize;

                while ((batch = generatedMessages.Skip(skip).Take(1000).ToList()).Count > 0)
                {
                    skip += batchSize;
                    var providerEarningsAdditionalMessages = new RecordEarningsJobAdditionalMessages
                    {
                        JobId             = jobId,
                        GeneratedMessages = batch,
                    };
                    await messageSession.Send(partitionedEndpointName, providerEarningsAdditionalMessages).ConfigureAwait(false);
                }
                logger.LogDebug($"Sent request(s) to record start of earnings job. Job Id: {jobId}, Ukprn: {ukprn}");
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to send the request to record the earnings job. Job: {jobId}, Error: {ex.Message}", ex);
                throw;
            }
        }
Beispiel #3
0
        public async Task RecordNewJobAdditionalMessages(RecordEarningsJobAdditionalMessages earningsJobRequest, CancellationToken cancellationToken)
        {
            await RecordJobInProgressMessages(earningsJobRequest.JobId, earningsJobRequest.GeneratedMessages, cancellationToken).ConfigureAwait(false);

            logger.LogDebug($"Finished storing new job messages for job: {earningsJobRequest.JobId}");
        }