Skip to content

Commit 88e9657

Browse files
authored
fix: Updated both job files 4 sidekiq (#13)
* feat: implement datadragon and player sync 1. Data Dragon Service - Busca dados estáticos da Riot 2. Região Configurável - Não mais hardcoded, usa player.region 3. Champion Mapping - Funcionando corretamente agora 4. 8 Novos API Endpoints - Para dados da Riot 5. 5 Rake Tasks - Gerenciamento de cache e sync 6. Suite de Testes - Criada para SyncPlayerFromRiotJob * chore: add admin bypass ruleset * feat(players): extract riot sync service - Create Players::Services::RiotSyncService - Extract Riot API logic from controller - Support import, sync, search operations - Add retry logic for better success * feat(players): extract stats service - Create Players::Services::StatsService (90 lines) - Extract statistics calculation - Calculate win rate, KDA, recent form - Make stats reusable and testable * refactor(players): migrate controller to module - Move to Players::Controllers namespace - Reduce from 750 to 350 lines (-53%) - Use services for business logic - Create proxy for backwards compatibility * refactor(players): migrate serializers and jobs - Move serializers to Players module - Move jobs to Players module - Organize all players domain code * refactor(auth): migrate authentication module - Move AuthController to module - Move User and Organization serializers - JwtService already in module - Create proxy controller * refactor: migrate matches, schedules, team goals - Migrate 3 core business modules - Organize by domain functionality - Create proxies for all * refactor: migrate analytics module - Migrate 7 analytics controllers - Organize performance analysis - Maintain namespace structure * refactor: migrate scouting module - Migrate scouting controllers - Move serializers and jobs - Organize talent discovery * refactor: migrate riot integration - Migrate 2 Riot controllers - Move 2 services to module - Consolidate Riot API functionality * refactor: migrate vod reviews and dashboard - Migrate VOD Reviews (2 controllers) - Migrate Dashboard module - Organize video review features * refactor: migrate dashboard to modular arc - Migrate Dashboard module * docs: finalize migration and update gitignore - Update gitignore for backups - Complete modular architecture migration * fix: Updated both job files 4 sidekiq (#12) 1. Use /lol/league/v4/entries/by-puuid/{puuid} instead of /by-summoner/{id} 2. Added new method fetch_ranked_stats_by_puuid as a workaround
1 parent 041c1cb commit 88e9657

3 files changed

Lines changed: 47 additions & 11 deletions

File tree

app/jobs/sync_player_from_riot_job.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ class SyncPlayerFromRiotJob < ApplicationJob
44
def perform(player_id)
55
player = Player.find(player_id)
66

7-
# Check if player has necessary data
87
unless player.riot_puuid.present? || player.summoner_name.present?
98
player.update(sync_status: 'error', last_sync_at: Time.current)
109
Rails.logger.error "Player #{player_id} missing Riot info"
1110
return
1211
end
1312

14-
# Get Riot API key
1513
riot_api_key = ENV['RIOT_API_KEY']
1614
unless riot_api_key.present?
1715
player.update(sync_status: 'error', last_sync_at: Time.current)
@@ -20,20 +18,18 @@ def perform(player_id)
2018
end
2119

2220
begin
23-
# Use player's region or default to BR1
2421
region = player.region.presence&.downcase || 'br1'
2522

26-
# Fetch summoner data
2723
if player.riot_puuid.present?
2824
summoner_data = fetch_summoner_by_puuid(player.riot_puuid, region, riot_api_key)
2925
else
3026
summoner_data = fetch_summoner_by_name(player.summoner_name, region, riot_api_key)
3127
end
3228

33-
# Fetch ranked stats
34-
ranked_data = fetch_ranked_stats(summoner_data['id'], region, riot_api_key)
29+
# Use PUUID for league endpoint (workaround for Riot API bug where summoner_data['id'] is nil)
30+
# See: https://github.com/RiotGames/developer-relations/issues/1092
31+
ranked_data = fetch_ranked_stats_by_puuid(player.riot_puuid, region, riot_api_key)
3532

36-
# Update player data
3733
update_data = {
3834
riot_puuid: summoner_data['puuid'],
3935
riot_summoner_id: summoner_data['id'],
@@ -43,7 +39,6 @@ def perform(player_id)
4339
last_sync_at: Time.current
4440
}
4541

46-
# Update ranked stats if available
4742
solo_queue = ranked_data.find { |q| q['queueType'] == 'RANKED_SOLO_5x5' }
4843
if solo_queue
4944
update_data.merge!({
@@ -85,7 +80,6 @@ def fetch_summoner_by_name(summoner_name, region, api_key)
8580
game_name, tag_line = summoner_name.split('#')
8681
tag_line ||= region.upcase
8782

88-
# Get PUUID from Riot ID
8983
account_url = "https://americas.api.riotgames.com/riot/account/v1/accounts/by-riot-id/#{URI.encode_www_form_component(game_name)}/#{URI.encode_www_form_component(tag_line)}"
9084
account_uri = URI(account_url)
9185
account_request = Net::HTTP::Get.new(account_uri)
@@ -144,4 +138,24 @@ def fetch_ranked_stats(summoner_id, region, api_key)
144138

145139
JSON.parse(response.body)
146140
end
141+
142+
def fetch_ranked_stats_by_puuid(puuid, region, api_key)
143+
require 'net/http'
144+
require 'json'
145+
146+
url = "https://#{region}.api.riotgames.com/lol/league/v4/entries/by-puuid/#{puuid}"
147+
uri = URI(url)
148+
request = Net::HTTP::Get.new(uri)
149+
request['X-Riot-Token'] = api_key
150+
151+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
152+
http.request(request)
153+
end
154+
155+
unless response.is_a?(Net::HTTPSuccess)
156+
raise "Riot API Error: #{response.code} - #{response.body}"
157+
end
158+
159+
JSON.parse(response.body)
160+
end
147161
end

app/modules/players/jobs/sync_player_from_riot_job.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def perform(player_id)
2626
summoner_data = fetch_summoner_by_name(player.summoner_name, region, riot_api_key)
2727
end
2828

29-
ranked_data = fetch_ranked_stats(summoner_data['id'], region, riot_api_key)
29+
# Use PUUID for league endpoint (workaround for Riot API bug where summoner_data['id'] is nil)
30+
# See: https://github.com/RiotGames/developer-relations/issues/1092
31+
ranked_data = fetch_ranked_stats_by_puuid(player.riot_puuid, region, riot_api_key)
3032

3133
update_data = {
3234
riot_puuid: summoner_data['puuid'],
@@ -136,4 +138,24 @@ def fetch_ranked_stats(summoner_id, region, api_key)
136138

137139
JSON.parse(response.body)
138140
end
141+
142+
def fetch_ranked_stats_by_puuid(puuid, region, api_key)
143+
require 'net/http'
144+
require 'json'
145+
146+
url = "https://#{region}.api.riotgames.com/lol/league/v4/entries/by-puuid/#{puuid}"
147+
uri = URI(url)
148+
request = Net::HTTP::Get.new(uri)
149+
request['X-Riot-Token'] = api_key
150+
151+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
152+
http.request(request)
153+
end
154+
155+
unless response.is_a?(Net::HTTPSuccess)
156+
raise "Riot API Error: #{response.code} - #{response.body}"
157+
end
158+
159+
JSON.parse(response.body)
160+
end
139161
end

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ services:
6767
condition: service_healthy
6868
redis:
6969
condition: service_healthy
70-
command: bundle exec sidekiq
70+
command: bundle exec sidekiq -C config/sidekiq.yml
7171

7272
volumes:
7373
postgres_data:

0 commit comments

Comments
 (0)