예제 #1
0
        private async Task GetGamesToWrite(List <Game> gamesToWrite, CancellationToken cancellationToken)
        {
            var apiGames = new List <ApiGamePlay>();

            //Get the responses
            foreach (var game in gamesToWrite)
            {
                GameDetail gameDetail;

                try
                {
                    gameDetail = await _gamePlayRepository.GetGamePlaysAsync(game, cancellationToken);
                }
                catch (Exception e)
                {
                    _logger.LogCritical(e, $"Failed to get game: {game.GameId}");
                    throw;
                }

                if (gameDetail.Game == null)
                {
                    continue;
                }

                apiGames.Add(new ApiGamePlay(gameDetail));
            }

            _channel.Writer.TryWrite(apiGames);
        }
예제 #2
0
        private async IAsyncEnumerable <ApiGamePlay> QueryForGameStats(
            PlayByPlayQueryParameter queryParameter,
            [EnumeratorCancellation] CancellationToken cancellationToken)
        {
            var scope = _tracer.BuildTrace(nameof(QueryForGameStats));

            scope.LogStart(nameof(QueryForGameStats));

            var games = await GetGamesFromQueryOptions(queryParameter, cancellationToken);

            games = games.Where(game => game.Gameday < DateTime.UtcNow.Date).ToList();

            if (!games.Any())
            {
                yield return(null);
            }

            var requests = games
                           .OrderByDescending(game => game.Gameday)
                           .Select(game => _gamePlayRepository.GetGamePlaysAsync(game, cancellationToken))
                           .ToList();

            //Wait for all the requests to finish
            await Task.WhenAll(requests);

            //Get the responses
            foreach (var request in requests)
            {
                var pbp = await request;

                if (pbp.Game == null)
                {
                    continue;
                }

                yield return(new ApiGamePlay(pbp));
            }

            scope.LogEnd(nameof(QueryForGameStats));
        }