public async Task UpdateBankHolidaysAsync()
        {
            var client   = new RestClient(_config.Url);
            var request  = new RestRequest();
            var response = await client.ExecuteTaskAsync <BankHolidays.BankHolidaysData>(request);

            if (!response.IsSuccessful)
            {
                throw new Exception($"Error getting list of bank holidays from url:{_config.Url}. Error:{response.ErrorMessage}");
            }

            if (!response.Data.EnglandAndWales.Events.Any())
            {
                throw new Exception($"Expected a non-empty list of bank holidays from url:{_config.Url}");
            }

            var bankHolidaysFromApi = new BankHolidays
            {
                Data = response.Data
            };

            if (await HasBankHolidayDataChanged(bankHolidaysFromApi))
            {
                await _referenceDataWriter.UpsertReferenceData(bankHolidaysFromApi);

                _logger.LogInformation($"Upserted bank holidays into ReferenceData store. Last England and Wales date:{bankHolidaysFromApi.Data.EnglandAndWales.Events.Last().Date}");
            }
            else
            {
                _logger.LogInformation("ReferenceData not updated as there is no change.");
            }
        }
예제 #2
0
        public async Task UpdateApprenticeshipProgrammesAsync()
        {
            var standardsTask  = GetStandards();
            var frameworksTask = GetFrameworks();
            var tasks          = new List <Task> {
                standardsTask, frameworksTask
            };

            try
            {
                Task.WaitAll(tasks.ToArray());

                var standardsFromApi  = standardsTask.Result.ToList();
                var frameworksFromApi = frameworksTask.Result.ToList();

                if (standardsFromApi.Count == 0)
                {
                    throw new InfrastructureException("Retrieved 0 standards from the apprenticeships api.");
                }

                if (frameworksFromApi.Count == 0)
                {
                    throw new InfrastructureException("Retrieved 0 frameworks from the apprenticeships api.");
                }

                var newList = new List <ApprenticeshipProgramme>();
                newList.AddRange(standardsFromApi);
                newList.AddRange(frameworksFromApi);

                await _referenceDataWriter.UpsertReferenceData(new ApprenticeshipProgrammes
                {
                    Data = newList.Distinct(new ApprenticeshipProgrammeEqualityComparer()).ToList()
                });

                _logger.LogInformation("Inserted: {standardCount} standards and {frameworkCount} frameworks.", standardsFromApi.Count, frameworksFromApi.Count);
            }
            catch (AggregateException)
            {
                if (standardsTask.Exception != null)
                {
                    _logger.LogError(standardsTask.Exception, "Failed to get standards from api");
                }

                if (frameworksTask.Exception != null)
                {
                    _logger.LogError(frameworksTask.Exception, "Failed to get frameworks from api");
                }

                throw;
            }
        }
예제 #3
0
        public async Task UpdateProviders()
        {
            try
            {
                var providersTask = await GetProviders();

                await _referenceDataWriter.UpsertReferenceData(new TrainingProviders {
                    Data = providersTask.ToList()
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to get providers from api");

                throw;
            }
        }
        public async Task RefreshBlockedEmployerAccountsAsync([TimerTrigger(Schedules.Hourly, RunOnStartup = true)] TimerInfo timerInfo, TextWriter log)
#endif
        {
            if (_jobsConfig.DisabledJobs.Contains(this.GetType().Name))
            {
                _logger.LogDebug($"{this.GetType().Name} is disabled, skipping ...");
                return;
            }

            _logger.LogInformation("Starting rebuilding blocked employers reference data.");

            var accountsTask   = _accountsReader.GetEmployerAccountsAsync();
            var levyPayersTask = _accountsReader.GetLevyPayerAccountIdsAsync();

            await Task.WhenAll(accountsTask, levyPayersTask);

            var accounts   = accountsTask.Result;
            var levyPayers = levyPayersTask.Result;

            const string id = "2";

            if (levyPayers.Contains(id) == false)
            {
                levyPayers.Add(id);
            }

            var nonLevyPayers = accounts.Where(x => levyPayers.Contains(x.AccountId) == false)
                                .Select(x => x.HashedAccountId)
                                .ToList();

            await _referenceDataWriter.UpsertReferenceData <BlockedEmployers>(new BlockedEmployers
            {
                Id = nameof(BlockedEmployers),
                EmployerAccountIds = nonLevyPayers
            });

            _logger.LogInformation("Finished rebuilding blocked employers reference data.");
        }
        public async Task UpdateApprenticeshipProgrammesAsync()
        {
            try
            {
                var trainingProgrammesTask = await GetTrainingProgrammes();

                var trainingProgrammesFromApi = trainingProgrammesTask.ToList();

                var standardsCount = trainingProgrammesFromApi.Count(c => c.ApprenticeshipType == TrainingType.Standard);
                if (standardsCount == 0)
                {
                    throw new InfrastructureException("Retrieved 0 standards from the apprenticeships api.");
                }

                var frameworksCount = trainingProgrammesFromApi.Count(c => c.ApprenticeshipType == TrainingType.Framework);
                if (frameworksCount == 0)
                {
                    throw new InfrastructureException("Retrieved 0 frameworks from the apprenticeships api.");
                }


                await ValidateList(trainingProgrammesFromApi);

                await _referenceDataWriter.UpsertReferenceData(new ApprenticeshipProgrammes {
                    Data = trainingProgrammesFromApi.Distinct(new ApprenticeshipProgrammeEqualityComparer()).ToList()
                });

                _logger.LogInformation("Inserted: {standardCount} standards and {frameworkCount} frameworks.", standardsCount, frameworksCount);
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to get training programmes from api");

                throw;
            }
        }