Class: Ratr::ParallelHttpProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/ratr/parallel_http_processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ParallelHttpProcessor

Returns a new instance of ParallelHttpProcessor.



4
5
6
7
# File 'lib/ratr/parallel_http_processor.rb', line 4

def initialize(options={})
  @concurrency = options.fetch(:concurrency, 2)
  @http_adapter = options[:http_adapter]
end

Instance Attribute Details

#concurrencyObject (readonly)

Returns the value of attribute concurrency.



3
4
5
# File 'lib/ratr/parallel_http_processor.rb', line 3

def concurrency
  @concurrency
end

#http_adapterObject (readonly)

Returns the value of attribute http_adapter.



3
4
5
# File 'lib/ratr/parallel_http_processor.rb', line 3

def http_adapter
  @http_adapter
end

Instance Method Details

#parallel_managerObject



15
16
17
# File 'lib/ratr/parallel_http_processor.rb', line 15

def parallel_manager
  @parallel_manager ||= Typhoeus::Hydra.new(max_concurrency: concurrency)
end

#process(&block) ⇒ Object



9
10
11
12
13
# File 'lib/ratr/parallel_http_processor.rb', line 9

def process(&block)
  http_adapter.in_parallel(parallel_manager) do
    block.call
  end
end