Class: QueueingProxy::Worker::Upstream

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/queueing_proxy/worker.rb

Overview

Defferable upstream connection

Defined Under Namespace

Modules: Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload, host, port, timeout, logger) ⇒ Upstream

Returns a new instance of Upstream.



104
105
106
107
# File 'lib/queueing_proxy/worker.rb', line 104

def initialize(payload, host, port, timeout, logger)
  @response = Http::Parser.new
  @payload, @host, @port, @timeout, @logger = payload, host, port, timeout, logger
end

Instance Attribute Details

#hostObject

Returns the value of attribute host.



101
102
103
# File 'lib/queueing_proxy/worker.rb', line 101

def host
  @host
end

#loggerObject

Returns the value of attribute logger.



101
102
103
# File 'lib/queueing_proxy/worker.rb', line 101

def logger
  @logger
end

#payloadObject

Returns the value of attribute payload.



101
102
103
# File 'lib/queueing_proxy/worker.rb', line 101

def payload
  @payload
end

#portObject

Returns the value of attribute port.



101
102
103
# File 'lib/queueing_proxy/worker.rb', line 101

def port
  @port
end

#responseObject (readonly)

Returns the value of attribute response.



102
103
104
# File 'lib/queueing_proxy/worker.rb', line 102

def response
  @response
end

#timeoutObject

Returns the value of attribute timeout.



101
102
103
# File 'lib/queueing_proxy/worker.rb', line 101

def timeout
  @timeout
end

Instance Method Details

#requestObject

Connect to the upstream server and send the HTTP payload



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/queueing_proxy/worker.rb', line 110

def request
  begin
    EventMachine.connect(host, port, Client) {|c|
      c.upstream = self
      c.comm_inactivity_timeout = timeout
      c.pending_connect_timeout = timeout
    }
    # TODO - Is this async/deferrable?
  rescue => e
    logger.error e
    fail # If something explodes here, fail the defferable
  end
  self
end