Skip to content

Commit bd3b36c

Browse files
committed
fix: solve organization Issue in SyncMatchJob
1 parent 60743df commit bd3b36c

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

app/jobs/sync_match_job.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,31 @@ class SyncMatchJob < ApplicationJob
88

99
def perform(match_id, organization_id, region = 'BR')
1010
organization = Organization.find(organization_id)
11-
riot_service = RiotApiService.new
1211

13-
match_data = riot_service.get_match_details(
14-
match_id: match_id,
15-
region: region
16-
)
12+
# Set organization context for the background job
13+
Current.set(organization_id: organization_id) do
14+
riot_service = RiotApiService.new
1715

18-
# Check if match already exists
19-
match = Match.find_by(riot_match_id: match_data[:match_id])
20-
if match.present?
21-
Rails.logger.info("Match #{match_id} already exists")
22-
return
23-
end
16+
match_data = riot_service.get_match_details(
17+
match_id: match_id,
18+
region: region
19+
)
2420

25-
# Create match record
26-
match = create_match_record(match_data, organization)
21+
# Check if match already exists
22+
match = Match.find_by(riot_match_id: match_data[:match_id])
23+
if match.present?
24+
Rails.logger.info("Match #{match_id} already exists")
25+
return
26+
end
27+
28+
# Create match record
29+
match = create_match_record(match_data, organization)
2730

28-
# Create player match stats
29-
create_player_match_stats(match, match_data[:participants], organization)
31+
# Create player match stats
32+
create_player_match_stats(match, match_data[:participants], organization)
3033

31-
Rails.logger.info("Successfully synced match #{match_id}")
34+
Rails.logger.info("Successfully synced match #{match_id}")
35+
end
3236
rescue RiotApiService::NotFoundError => e
3337
Rails.logger.error("Match not found in Riot API: #{match_id} - #{e.message}")
3438
rescue StandardError => e

0 commit comments

Comments
 (0)