You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

15 lines
580 B

# Resolves a player's country from their request IP in the background, so the
# external geolocation call never delays the start of the game. Enqueued by
# GameController#start only when no explicit ?country= override was given.
class ResolvePlayerCountryJob < ApplicationJob
queue_as :default
def perform(player_id, ip)
player = Player.find_by(id: player_id)
return if player.nil? || player.country.present?
code = Geocoder.search(ip).first&.country_code
country = Player.valid_country_code(code)
player.update(country: country) if country
end
end