Class: ResqueKalashnikov::HttpRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/resque_kalashnikov/http_request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ HttpRequest

Returns a new instance of HttpRequest.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/resque_kalashnikov/http_request.rb', line 7

def initialize(*args)
  case args.size
    when 1 then @url = args[0]
    when 2 then @url, @opts = args
    when 3 then @url, @http_method, @opts = args
  else
    raise "insufficient params in #{self.class}: args=#{args}"
  end
  @http_method ||= 'get'
  @opts ||= {}
  @http_method.downcase!
end

Instance Attribute Details

#http_methodObject

Returns the value of attribute http_method.



5
6
7
# File 'lib/resque_kalashnikov/http_request.rb', line 5

def http_method
  @http_method
end

#optsObject

Returns the value of attribute opts.



5
6
7
# File 'lib/resque_kalashnikov/http_request.rb', line 5

def opts
  @opts
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/resque_kalashnikov/http_request.rb', line 5

def url
  @url
end

Class Method Details

.perform(*args) ⇒ Object



59
60
61
# File 'lib/resque_kalashnikov/http_request.rb', line 59

def perform(*args)
  new(*args).perform
end

Instance Method Details

#handle(http) ⇒ Object

This method is invoked inside EM no blocking calls, please



22
23
24
# File 'lib/resque_kalashnikov/http_request.rb', line 22

def handle http
  Resque::Catridge.new(self, http)
end

#performObject



30
31
32
33
34
# File 'lib/resque_kalashnikov/http_request.rb', line 30

def perform
  catrige = handle http_request
  reload if catrige.reload? && catrige.retries < retry_limit
  http_request.response
end

#reload_optsObject



36
37
38
# File 'lib/resque_kalashnikov/http_request.rb', line 36

def reload_opts
  opts
end

#retry_limitObject



26
27
28
# File 'lib/resque_kalashnikov/http_request.rb', line 26

def retry_limit
  instance_variable_get(:@retry_limit) || 2
end