Beispiel #1
0
        public async Task ProcessProviderAsync(string academicYear, int ukprn, CancellationToken cancellationToken)
        {
            var firstPageOfLearners = await _sldClient.ListLearnersForProviderAsync(academicYear, ukprn, 1, cancellationToken);

            var state = await _stateStore.GetProviderStateAsync(academicYear, ukprn, cancellationToken);

            var difference = state == null || state.NumberOfLearners == 0 ? 0m : Math.Abs(1 - (firstPageOfLearners.TotalNumberOfItems / (decimal)state.NumberOfLearners));

            if (state == null || difference <= 0.1m || state.IgnoredSubmissionCount >= 4)
            {
                for (var i = 1; i <= firstPageOfLearners.TotalNumberOfPages; i++)
                {
                    await _learnerQueue.EnqueueAsync(new LearnerQueueItem
                    {
                        AcademicYear = academicYear,
                        Ukprn        = ukprn,
                        PageNumber   = i,
                    }, cancellationToken);
                }

                await _stateStore.SetProviderStateAsync(new ProviderState
                {
                    AcademicYear           = academicYear,
                    Ukprn                  = ukprn,
                    NumberOfLearners       = firstPageOfLearners.TotalNumberOfItems,
                    IgnoredSubmissionCount = 0,
                }, cancellationToken);
            }
            else
            {
                state.IgnoredSubmissionCount++;
                await _stateStore.SetProviderStateAsync(state, cancellationToken);
            }
        }