Class: Maintenance::AtlasEngine::ElasticsearchIndexCreateTask

Inherits:
MaintenanceTasks::Task
  • Object
show all
Extended by:
T::Sig
Includes:
AtlasEngine::LogHelper
Defined in:
app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AtlasEngine::LogHelper

#log_error, #log_info, #log_warn

Instance Attribute Details

#repositoryObject



52
53
54
55
56
57
58
59
# File 'app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb', line 52

def repository
  @repository ||= ::AtlasEngine::CountryRepository.new(
    country_code: T.must(country_code),
    repository_class: ::AtlasEngine.elasticsearch_repository.constantize,
    locale: sanitized_locale,
    index_configuration: index_configuration,
  )
end

Instance Method Details

#collectionObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb', line 24

def collection
  @batch_number = 0
  batch_size = 2000

  sanitized_country_code = validate(T.must(country_code))

  address_conditions = {
    country_code: sanitized_country_code,
    province_code: sanitized_province_codes,
    locale: sanitized_locale,
  }.compact_blank

  record_count = ::AtlasEngine::PostAddress.where(address_conditions).size
  raise "No records to process for country code: #{country_code}" if record_count.zero?

  repository.create_next_index(ensure_clean: true, raise_errors: true)

  ::AtlasEngine::PostAddress.where(address_conditions).in_batches(of: batch_size)
end

#process(batch_of_post_address) ⇒ Object



45
46
47
48
49
# File 'app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb', line 45

def process(batch_of_post_address)
  log_info("Processing batch #{@batch_number} for repository #{repository.read_alias_name.upcase}.")
  repository.save_records_backfill(batch_of_post_address)
  @batch_number += 1
end

#switch_indexObject



62
63
64
65
66
67
# File 'app/tasks/maintenance/atlas_engine/elasticsearch_index_create_task.rb', line 62

def switch_index
  if activate_index
    repository.switch_to_next_index
    log_info("Switched index `#{repository.read_alias_name}` live.")
  end
end