class Resque::Cluster::Member

Member is a single member of a resque pool cluster

Attributes

config[R]
hostname[R]
pool[R]

Public Class Methods

new(started_pool) click to toggle source
# File lib/resque/cluster/member.rb, line 10
def initialize(started_pool)
  @pool = started_pool
  @config = Config.new(Cluster.config[:local_config_path], Cluster.config[:global_config_path])
  if @config.verified?
    @config.log_warnings
    @worker_count_manager = initialize_gru
  else
    @config.log_errors
    @pool.premature_quit
  end
end

Public Instance Methods

check_for_worker_count_adjustment() click to toggle source
# File lib/resque/cluster/member.rb, line 31
def check_for_worker_count_adjustment
  return unless gru_is_inititalized?
  host_count_adjustment = @worker_count_manager.adjust_workers
  adjust_worker_counts(host_count_adjustment) if host_count_adjustment
end
perform() click to toggle source
# File lib/resque/cluster/member.rb, line 22
def perform
  check_for_worker_count_adjustment
end
unregister() click to toggle source
# File lib/resque/cluster/member.rb, line 26
def unregister
  remove_counts
  unqueue_all_workers
end

Private Instance Methods

adjust_worker_counts(count_adjustments) click to toggle source
# File lib/resque/cluster/member.rb, line 59
def adjust_worker_counts(count_adjustments)
  count_adjustments.each do |worker, count|
    next if count == 0
    @pool.adjust_worker_counts(worker, count)
    update_counts
  end
end
global_prefix() click to toggle source
# File lib/resque/cluster/member.rb, line 39
def global_prefix
  "cluster:#{Cluster.config[:cluster_name]}:#{Cluster.config[:environment]}"
end
gru_is_inititalized?() click to toggle source
# File lib/resque/cluster/member.rb, line 89
def gru_is_inititalized?
  ! @worker_count_manager.nil?
end
initialize_gru() click to toggle source
# File lib/resque/cluster/member.rb, line 51
def initialize_gru
  Gru.create(@config.gru_format)
end
member_prefix() click to toggle source
# File lib/resque/cluster/member.rb, line 43
def member_prefix
  "#{global_prefix}:#{hostname}"
end
remove_counts() click to toggle source
# File lib/resque/cluster/member.rb, line 67
def remove_counts
  Resque.redis.del(running_workers_key_name)
end
running_workers_key_name() click to toggle source
# File lib/resque/cluster/member.rb, line 47
def running_workers_key_name
  "#{member_prefix}:running_workers"
end
unqueue_all_workers() click to toggle source
# File lib/resque/cluster/member.rb, line 71
def unqueue_all_workers
  @worker_count_manager.release_workers if gru_is_inititalized?
end
unqueue_workers(workers) click to toggle source
# File lib/resque/cluster/member.rb, line 75
def unqueue_workers(workers)
  workers = Array(workers)
  workers.each do |worker|
    @worker_count_manager.release_workers(worker) if gru_is_inititalized?
  end
end
update_counts() click to toggle source
# File lib/resque/cluster/member.rb, line 82
def update_counts
  current_workers = @pool.config
  current_workers.each do |key, value|
    Resque.redis.hset(running_workers_key_name, key, value)
  end
end