private async Task GetAllPlaysAsync(BoardGame boardGame) { int page = 1; GetPlaysResult result; _logger.Information("Removing any existing plays for {BoardGameName}", boardGame.Name); await _mongoSvc.DeletePlaysFor(boardGame.ObjectId, _cancellationToken); _logger.Information("Starting play import for {BoardGameName}", boardGame.Name); do { result = await _bggSvc.GetPlaysAsync(boardGame.ObjectId, page); if (result.TooManyRequests) { _logger.Warning("Too many requests, will wait to resume..."); await Task.Delay(TimeSpan.FromSeconds(60), _cancellationToken); continue; } if (!result.WasSuccessful) { _logger.Error("Failed to get plays, not sure what to do now..."); continue; } _logger.Information( "Successfully downloaded page {CurrentPage} of {TotalPages}", result.Page, Math.Ceiling(result.TotalCount / 100d)); await _mongoSvc.InsertPlaysAsync(boardGame, result.Plays, _cancellationToken); page++; } while ((!result.WasSuccessful || result.Plays.Count == MaxPlaysPerPage) && !_cancellationToken.IsCancellationRequested); await _mongoSvc.UpsertBoardGameStatusAsync( new BoardGameStatus { Id = ObjectId.GenerateNewId(), ObjectId = boardGame.ObjectId, BoardGameName = boardGame.Name, ImportSuccessful = true, LastUpdated = DateTime.Now }, _cancellationToken); }