Class: Resque::Catridge

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/catridge.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Catridge

Returns a new instance of Catridge.



5
6
7
8
9
10
# File 'lib/resque/catridge.rb', line 5

def initialize(request, response)
  @request = request
  @response = response
  log if misfire?
  inc_stat_counter
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/resque/catridge.rb', line 3

def request
  @request
end

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/resque/catridge.rb', line 3

def response
  @response
end

Class Method Details

.misfire_codesObject



65
66
67
# File 'lib/resque/catridge.rb', line 65

def misfire_codes
  redis.keys "#{ns}:misfires:*"
end

.misfire_stats(status) ⇒ Object



69
70
71
72
# File 'lib/resque/catridge.rb', line 69

def misfire_stats(status)
  redis.hgetall "#{status}"
  #redis.hgetall "#{ns}:misfires:#{status}"
end

.misfire_stats_reset(status, request) ⇒ Object



74
75
76
77
# File 'lib/resque/catridge.rb', line 74

def misfire_stats_reset(status, request)
  redis.hdel "#{status}", "#{request}"
  #redis.hgetall "#{ns}:misfires:#{status}"
end

.nsObject



52
53
54
# File 'lib/resque/catridge.rb', line 52

def ns
  'kalashnikov'
end

.redisObject

DI here, please



57
58
59
# File 'lib/resque/catridge.rb', line 57

def redis
  Resque.redis
end

.reset_statsObject



79
80
81
82
83
84
# File 'lib/resque/catridge.rb', line 79

def reset_stats
  stats.keys.each do |http_code|
    redis.del "#{ns}:misfires:#{http_code}"
  end
  redis.del "#{ns}:stat"
end

.statsObject



61
62
63
# File 'lib/resque/catridge.rb', line 61

def stats
  redis.hgetall "#{ns}:stat"
end

Instance Method Details

#reload?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/resque/catridge.rb', line 12

def reload?
  misfire? && !ran_out_of_ammo? 
end

#retriesObject



16
17
18
# File 'lib/resque/catridge.rb', line 16

def retries
  self.class.redis.hget("#{self.class.ns}:misfires:#{status}", serialized_request).to_i
end