public GraphQLService(ILogger <GraphQLService> logger, ICountryService countryService, GitHubModel gitHubModel) { _logger = logger; _countryService = countryService; _gitHubModel = gitHubModel; countryModel = _gitHubModel.Country.First(); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { _graphQLHttpClient = new GraphQLContext(await new RestContext().RequestGitHubAuthorizationKeys()).graphQLHttpClient; while (!stoppingToken.IsCancellationRequested) { if (hasNextPage) { if (numberOfRequests <= _gitHubModel.MaxNumberOfRequests) { _logger.LogInformation("Country {country}", countryModel.Name); try { graphQLResponseModel = await AddUser(new GraphQLRequestModel(countryModel, _gitHubModel.MaxRequestSize, endCursor)); hasNextPage = graphQLResponseModel.Data.search.pageInfo.hasNextPage; endCursor = graphQLResponseModel.Data.search.pageInfo.endCursor; numberOfRequests = numberOfRequests + 1; _logger.LogInformation("Response {responseHeader}", graphQLResponseModel.ResponseHeaders.ToString()); _logger.LogInformation("Added Users hasNextPage {hasNextPage} endCursor {endCursor}", hasNextPage, endCursor); } catch (Exception e) { hasNextPage = false; _logger.LogInformation("Add Exception Some GraphQL Server Error {Exception}", e); } } else { hasNextPage = false; _logger.LogInformation("Max Cap NumberOfUsers"); await Task.Delay(TimeSpan.FromMinutes(_gitHubModel.DelayTaskTimeInMinutes), stoppingToken); } } else { _logger.LogInformation("No hasNextPage"); countryModel = GetCountryModel(countryModel.Name); numberOfRequests = 0; hasNextPage = true; endCursor = null; } await Task.Delay(TimeSpan.FromSeconds(_gitHubModel.ElapsedTimeInSeconds), stoppingToken); } }
public GraphQLRequestModel(GitHubModel.CountryModel country, int numberOfUsers, string endCursor) { Country = country; NumberOfUsers = numberOfUsers; EndCursor = endCursor; }