Class: RailsAutoscaleAgent::WorkerAdapters::Resque

Inherits:
Object
  • Object
show all
Includes:
Logger, Singleton
Defined in:
lib/rails_autoscale_agent/worker_adapters/resque.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logger

#logger

Instance Attribute Details

#queuesObject



13
14
15
# File 'lib/rails_autoscale_agent/worker_adapters/resque.rb', line 13

def queues
  @queues ||= ['default']
end

Instance Method Details

#collect!(store) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rails_autoscale_agent/worker_adapters/resque.rb', line 25

def collect!(store)
  log_msg = String.new
  current_queues = ::Resque.queues

  # Don't collect worker metrics if there are unreasonable number of queues
  if current_queues.size > Config.instance.max_queues
    logger.warn "Skipping Resque metrics - #{current_queues.size} queues exceeds the #{Config.instance.max_queues} queue limit"
    return
  end

  # Ensure we continue to collect metrics for known queue names, even when nothing is
  # enqueued at the time. Without this, it will appears that the agent is no longer reporting.
  self.queues |= current_queues

  queues.each do |queue|
    next if queue.nil? || queue.empty?
    depth = ::Resque.size(queue)
    store.push depth, Time.now, queue, :qd
    log_msg << "resque-qd.#{queue}=#{depth} "
  end

  logger.debug log_msg
end

#enabled?Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/rails_autoscale_agent/worker_adapters/resque.rb', line 17

def enabled?
  require 'resque'
  logger.info "Resque enabled"
  true
rescue LoadError
  false
end