Beispiel #1
0
        public async Task ProcessChangesAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Getting last date UKRLP was checked");
            var lastCheckedState = await _stateStore.GetStateAsync("LastChecked", cancellationToken);

            DateTime lastChecked;

            if (string.IsNullOrEmpty(lastCheckedState))
            {
                lastChecked = DateTime.Today;
                _logger.LogInformation("Never checked UKRLP for changes before. Starting from {ChangedSinceDate}",
                                       lastChecked.ToString("O"));
            }
            else
            {
                lastChecked = DateTime.Parse(lastCheckedState);
                _logger.LogInformation("Getting changes since {ChangedSinceDate}",
                                       lastChecked.ToString("O"));
            }

            var changedProviders = await _ukrlpApiClient.GetProvidersChangedSinceAsync(lastChecked, cancellationToken);

            _logger.LogInformation("Found {NumberOfProvidersChanged} changed providers since {ChangedSinceDate}",
                                   changedProviders.Length, lastChecked);

            lastChecked = DateTime.Now;

            foreach (var provider in changedProviders)
            {
                await _ukrlpDataReceiver.SendDataAsync(provider, cancellationToken);
            }

            await _stateStore.SetStateAsync("LastChecked", lastChecked.ToString("O"), cancellationToken);
        }
Beispiel #2
0
        public async Task <ApprenticeshipProvider[]> GetDataAsync(CancellationToken cancellationToken)
        {
            var downloadLink = await GetDownloadLinkAsync(cancellationToken);

            var isNewDownloadLink = await IsNewDownloadLink(downloadLink, cancellationToken);

            if (!isNewDownloadLink)
            {
                _logger.LogInformation("Download link has not changed");
                return(new ApprenticeshipProvider[0]);
            }

            var csv = await DownloadCsvAsync(downloadLink, cancellationToken);

            var apprenticeshipProviders = ParseCsv(csv);

            await _stateStore.SetStateAsync(StateKeyDownloadLink, downloadLink, cancellationToken);

            return(apprenticeshipProviders);
        }