Class: Resque::Integration::FailureBackends::QueuesTotals

Inherits:
Failure::Base
  • Object
show all
Defined in:
lib/resque/integration/failure_backends/queues_totals.rb

Constant Summary collapse

MAX_COUNTER_VALUE =
10_000_000

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clear(queue = nil) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/resque/integration/failure_backends/queues_totals.rb', line 27

def self.clear(queue = nil)
  if queue.nil?
    Resque.redis.del(REDIS_COUNTER_KEY)
  else
    Resque.redis.hdel(REDIS_COUNTER_KEY, queue)
  end
end

.count(queue = nil, _class_name = nil) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/resque/integration/failure_backends/queues_totals.rb', line 19

def self.count(queue = nil, _class_name = nil)
  if queue.nil?
    Resque.redis.hvals(REDIS_COUNTER_KEY).map(&:to_i).sum
  else
    Resque.redis.hget(REDIS_COUNTER_KEY, queue).to_i
  end
end

.queuesObject



15
16
17
# File 'lib/resque/integration/failure_backends/queues_totals.rb', line 15

def self.queues
  Resque.redis.hkeys(REDIS_COUNTER_KEY)
end

Instance Method Details

#saveObject



10
11
12
13
# File 'lib/resque/integration/failure_backends/queues_totals.rb', line 10

def save
  current_value = Resque.redis.hincrby(REDIS_COUNTER_KEY, queue, 1)
  Resque.redis.hset(REDIS_COUNTER_KEY, queue, 1) if current_value >= MAX_COUNTER_VALUE
end