# 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