Class: Translations::ExportPackagesTranslationWorker

Inherits:
ApplicationWorker show all
Includes:
ElasticAPM::SpanHelpers
Defined in:
app/workers/translations/export_packages_translation_worker.rb

Overview

Generic worker to export package translations into an Excel file with AWS pre-filled translations. Supports: AYCE, Party Pack, Xperience, Buffet, Set Menu, Hungry at Home Translates: name, description, charge_policy Queue: longprocess for large datasets with external API calls.

Constant Summary collapse

EXPORT_COLUMNS =
%w[id package_type existing_locale field original_text target_locale translated_text].freeze
TRANSLATABLE_FIELDS =
%w[name description charge_policy].freeze
PACKAGE_MODELS =

Map package types to model classes

{
  'ayce' => HhPackage::Package::Ayce,
  'party_pack' => HhPackage::Package::PartyPack,
  'xperience' => HhPackage::Package::Xperience,
  'buffet' => HhPackage::Package::BuffetExtra,
  'set_menu' => HhPackage::Package::SetMenu,
  'hungry_at_home' => HhPackage::Package::HungryAtHome,
}.freeze
PACKAGE_TYPE_LABELS =
{
  'ayce' => 'AYCE',
  'party_pack' => 'Party Pack',
  'xperience' => 'Xperience',
  'buffet' => 'Buffet',
  'set_menu' => 'Set Menu',
  'hungry_at_home' => 'Hungry at Home',
}.freeze

Instance Method Summary collapse

Methods inherited from ApplicationWorker

unlimited_retry

Instance Method Details

#perform(package_type, target_locale, user_id) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/workers/translations/export_packages_translation_worker.rb', line 36

def perform(package_type, target_locale, user_id)
  @started_at = Time.current
  @package_type = package_type.to_s
  @target_locale = target_locale.to_sym
  @user = User.find_by(id: user_id)
  return unless @user

  unless PACKAGE_MODELS.key?(@package_type)
    raise ArgumentError, "Invalid package_type: #{@package_type}. Valid types: #{PACKAGE_MODELS.keys.join(', ')}"
  end

  raise ArgumentError, 'Target locale cannot be English; choose a non-English language.' if @target_locale == :en

  if defined?(BUSINESS_LOGGER)
    BUSINESS_LOGGER.set_business_context({ worker_class: self.class.name, user_id: @user.id,
                                           target_locale: @target_locale, package_type: @package_type })
  end
  BUSINESS_LOGGER.info('package_translation_export_start') if defined?(BUSINESS_LOGGER)

  I18n.with_locale(:en) do
    execute_export
  end
end