Class: Faraday::Adapter::EMSynchrony

Inherits:
Faraday::Adapter show all
Includes:
EMHttp::Options
Defined in:
lib/faraday/adapter/em_synchrony.rb,
lib/faraday/adapter/em_synchrony/parallel_manager.rb

Overview

EventMachine Synchrony adapter.

Defined Under Namespace

Classes: ParallelManager

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.setup_parallel_manager(_options = nil) ⇒ ParallelManager

Returns:


36
37
38
# File 'lib/faraday/adapter/em_synchrony.rb', line 36

def self.setup_parallel_manager(_options = nil)
  ParallelManager.new
end

Instance Method Details

#call(env) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/faraday/adapter/em_synchrony.rb', line 40

def call(env)
  super
  request = create_request(env)

  http_method = env[:method].to_s.downcase.to_sym

  if env[:parallel_manager]
    # Queue requests for parallel execution.
    execute_parallel_request(env, request, http_method)
  else
    # Execute single request.
    execute_single_request(env, request, http_method)
  end

  @app.call env
rescue Errno::ECONNREFUSED
  raise Faraday::ConnectionFailed, $ERROR_INFO
rescue EventMachine::Connectify::CONNECTError => e
  if e.message.include?('Proxy Authentication Required')
    raise Faraday::ConnectionFailed,
          %(407 "Proxy Authentication Required")
  end

  raise Faraday::ConnectionFailed, e
rescue Errno::ETIMEDOUT => e
  raise Faraday::TimeoutError, e
rescue RuntimeError => e
  if e.message == 'connection closed by server'
    raise Faraday::ConnectionFailed, e
  end

  raise Faraday::TimeoutError, e if e.message.include?('timeout error')

  raise
rescue StandardError => e
  if defined?(OpenSSL) && e.is_a?(OpenSSL::SSL::SSLError)
    raise Faraday::SSLError, e
  end

  raise
end

#create_request(env) ⇒ Object


82
83
84
85
86
87
# File 'lib/faraday/adapter/em_synchrony.rb', line 82

def create_request(env)
  EventMachine::HttpRequest.new(
    Utils::URI(env[:url].to_s),
    connection_config(env).merge(@connection_options)
  )
end