Class: Restify::Adapter::Typhoeus

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/restify/adapter/typhoeus.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'Expect' => '',
  'Transfer-Encoding' => ''
}.freeze
DEFAULT_OPTIONS =
{
  followlocation: true,
  tcp_keepalive: true,
  tcp_keepidle: 5,
  tcp_keepintvl: 5
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#_fmt, #debug, #logger

Methods inherited from Base

#call

Constructor Details

#initialize(sync: false, options: {}, **kwargs) ⇒ Typhoeus

Returns a new instance of Typhoeus.



26
27
28
29
30
31
32
33
34
35
# File 'lib/restify/adapter/typhoeus.rb', line 26

def initialize(sync: false, options: {}, **kwargs)
  @hydra   = ::Typhoeus::Hydra.new(**kwargs)
  @mutex   = Mutex.new
  @options = DEFAULT_OPTIONS.merge(options)
  @queue   = Queue.new
  @sync    = sync
  @thread  = nil

  super()
end

Instance Attribute Details

#syncObject (readonly)

Returns the value of attribute sync.



12
13
14
# File 'lib/restify/adapter/typhoeus.rb', line 12

def sync
  @sync
end

Instance Method Details

#call_native(request, writer) ⇒ Object

rubocop:disable Metrics/MethodLength



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/restify/adapter/typhoeus.rb', line 42

def call_native(request, writer)
  req = convert(request, writer)

  if sync?
    @hydra.queue(req)
    @hydra.run
  else
    debug 'request:add',
      tag: request.object_id,
      method: request.method.upcase,
      url: request.uri,
      timeout: request.timeout

    @queue << convert(request, writer)

    thread.run unless thread.status
  end
end

#sync?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/restify/adapter/typhoeus.rb', line 37

def sync?
  @sync
end