add geo info and do refractor on workers

This commit is contained in:
2021-04-29 20:44:21 +02:00
parent f7799bb514
commit c5190b48f8
32 changed files with 241 additions and 205 deletions

View File

@@ -1,24 +1,7 @@
# frozen_string_literal: true
class WowCharactersWorker
include Sidekiq::Worker
class WowCharactersWorker < WowSidekiqWorker
def perform(user_id)
locales = [
['en-us', 'en_US'],
['es-mx', 'es_MX'],
['pt-br', 'pt_BR'],
['de-de', 'de_DE'],
['en-gb', 'en_GB'],
['es-es', 'es_ES'],
['fr-fr', 'fr_FR'],
['it', 'it_IT'],
['ru-ru', 'ru_RU'],
['ko', 'ko_KR'],
['zh-tw', 'zh_TW'],
['zh-cn', 'zh_CN']
]
# Update the WoW character list
return unless (user = User.find(user_id))
@@ -29,7 +12,7 @@ class WowCharactersWorker
result.wow_accounts.each do |account|
account.characters.each do |character|
wow_char = user.wow_characters.where(character_id: character.id).first_or_initialize
wow_char = user.wow_characters.find_or_initialize_by(character_id: character.id)
wow_char.name = character.name
wow_char.gender = character.gender.type
@@ -40,8 +23,7 @@ class WowCharactersWorker
wow_char.wow_class = WowClass.where(class_id: character.playable_class.id).first
wow_char.wow_race = WowRace.where(race_id: character.playable_race.id).first
wow_char.user = user
wow_char.account_id = account.id
wow_char.character_id = character.id
wow_char.account_id = account.map_id
locales.each do |locale|
Mobility.with_locale(locale[0]) do
@@ -52,10 +34,11 @@ class WowCharactersWorker
wow_char.save
if wow_char.persisted?
WowCharacterMediaWorker.perform_async(wow_char.character_id)
WowCharacterDetailWorker.perform_async(wow_char.character_id)
end
next unless wow_char.persisted?
WowCharacterMediaWorker.perform_async(wow_char.character_id)
WowCharacterDetailWorker.perform_async(wow_char.character_id)
WowCharacterPositionsWorker.perform_async(wow_char.character_id)
end
end
end