Class: ElasticGraph::Local::IndexingCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_graph/local/indexing_coordinator.rb

Overview

Responsible for coordinating the generation and indexing of fake data batches. Designed to be pluggable with different publishing strategies.

Constant Summary collapse

PARALLELISM =
8

Instance Method Summary collapse

Constructor Details

#initialize(fake_data_batch_generator, output: $stdout, &publish_batch) ⇒ IndexingCoordinator

Returns a new instance of IndexingCoordinator.



20
21
22
23
24
# File 'lib/elastic_graph/local/indexing_coordinator.rb', line 20

def initialize(fake_data_batch_generator, output: $stdout, &publish_batch)
  @fake_data_batch_generator = fake_data_batch_generator
  @publish_batch = publish_batch
  @output = output
end

Instance Method Details

#index_fake_data(num_batches) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/elastic_graph/local/indexing_coordinator.rb', line 26

def index_fake_data(num_batches)
  batch_queue = ::Thread::Queue.new

  publishing_threads = Array.new(PARALLELISM) { new_publishing_thread(batch_queue) }

  num_batches.times do
    batch = [] # : ::Array[::Hash[::String, untyped]]
    @fake_data_batch_generator.call(batch)
    @output.puts "Generated batch of #{batch.size} documents..."
    batch_queue << batch
  end

  publishing_threads.map { batch_queue << :done }
  publishing_threads.each(&:join)

  @output.puts "...done."
end