Class: ResqueToCloudwatch::WorkRemainingCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/resque_to_cloudwatch/collectors.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ WorkRemainingCollector

Returns a new instance of WorkRemainingCollector.



71
72
73
# File 'lib/resque_to_cloudwatch/collectors.rb', line 71

def initialize(config)
  @config = config
end

Instance Method Details

#get_valueObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/resque_to_cloudwatch/collectors.rb', line 75

def get_value
  redis = Redis.new(:host => @config.redis_host, :port => @config.redis_port)
  working = redis.smembers('resque:workers').select do |worker_key|
    redis.exists("resque:worker:#{worker_key}")
  end.length
  queue_length = redis.smembers('resque:queues').map do |queue_key|
    redis.llen("resque:queue:#{queue_key}")
  end.reduce(:+)
  working + queue_length
end

#metric_nameObject



86
87
88
# File 'lib/resque_to_cloudwatch/collectors.rb', line 86

def metric_name
  "resque_work_remaining"
end

#to_sObject



90
91
92
# File 'lib/resque_to_cloudwatch/collectors.rb', line 90

def to_s
  metric_name
end