class Resque::Cluster::Config
Config
is a global and local configuration of a member of a resque pool cluster
Attributes
config[R]
configs[R]
global_config[R]
verifier[R]
Public Class Methods
new(config_path, global_config_path = nil)
click to toggle source
# File lib/resque/cluster/config.rb, line 12 def initialize(config_path, global_config_path = nil) @config = Config::File.new(config_path) @configs = [config] if global_config_path global_config = Config::File.new(global_config_path) if global_config.expand_path != config.expand_path @global_config = global_config @configs << global_config end end @errors = Set.new @verifier = Verifier.new(configs) end
Public Instance Methods
errors()
click to toggle source
# File lib/resque/cluster/config.rb, line 51 def errors @errors + configs.map { |config| config.errors.map { |error| "#{config}: #{error}" } }.flatten end
gru_format()
click to toggle source
# File lib/resque/cluster/config.rb, line 35 def gru_format return {} unless verified? { manage_worker_heartbeats: true, host_maximums: host_maximums, client_settings: gru_redis_connection, cluster_name: Cluster.config[:cluster_name], environment_name: Cluster.config[:environment], cluster_maximums: cluster_maximums, rebalance_flag: rebalance_flag || false, max_workers_per_host: max_workers_per_host || nil, presume_host_dead_after: presume_dead_after || 120 } end
log_errors()
click to toggle source
# File lib/resque/cluster/config.rb, line 65 def log_errors errors.each do |error| puts error end end
log_warnings()
click to toggle source
# File lib/resque/cluster/config.rb, line 59 def log_warnings warnings.each do |warning| puts warning end end
verified?()
click to toggle source
# File lib/resque/cluster/config.rb, line 31 def verified? verifier.verified? && complete_worker_config? end
warnings()
click to toggle source
# File lib/resque/cluster/config.rb, line 55 def warnings @warnings ||= [] end
Private Instance Methods
cluster_maximums()
click to toggle source
# File lib/resque/cluster/config.rb, line 110 def cluster_maximums case config_type when :separate global_config['global_maximums'] || global_config.contents.reject do |k, _| ['global_maximums', 'presume_dead_after', 'max_workers_per_host', 'rebalance_cluster'].include?(k) end when :old config['global_maximums'] when :new config['workers'].each.with_object({}) do |(pool, maximums), global_maximums| global_maximums[pool] = maximums['global'] end end end
complete_worker_config?()
click to toggle source
# File lib/resque/cluster/config.rb, line 86 def complete_worker_config? host_keys = Set.new(host_maximums.delete_if { |_, v| v.nil? }.keys) cluster_keys = Set.new(cluster_maximums.delete_if { |_, v| v.nil? }.keys) (host_keys == cluster_keys).tap do |complete| @errors << "Every worker configuration must contain a local and a global maximum." unless complete end end
config_type()
click to toggle source
# File lib/resque/cluster/config.rb, line 152 def config_type @config_type ||= if global_config :separate elsif config['workers'] :new else :old end end
gru_redis_connection()
click to toggle source
# File lib/resque/cluster/config.rb, line 73 def gru_redis_connection case config_type when :separate global_config['redis_client_options'] || Resque.redis.client.options when :old Resque.redis.client.options when :new config['redis_client_options'] || Resque.redis.client.options end end
host_maximums()
click to toggle source
# File lib/resque/cluster/config.rb, line 95 def host_maximums case config_type when :separate config.contents when :old config.contents.reject do |k, _| ['global_maximums', 'presume_dead_after', 'max_workers_per_host', 'rebalance_cluster'].include?(k) end when :new config['workers'].each.with_object({}) do |(pool, maximums), local_maximums| local_maximums[pool] = maximums['local'] end end end
max_workers_per_host()
click to toggle source
# File lib/resque/cluster/config.rb, line 134 def max_workers_per_host case config_type when :separate global_config['max_workers_per_host'] when :old, :new config['max_workers_per_host'] end end
presume_dead_after()
click to toggle source
# File lib/resque/cluster/config.rb, line 143 def presume_dead_after case config_type when :separate global_config['presume_dead_after'] when :old, :new config['presume_dead_after'] end end
rebalance_flag()
click to toggle source
# File lib/resque/cluster/config.rb, line 125 def rebalance_flag case config_type when :separate global_config['rebalance_cluster'] when :old, :new config['rebalance_cluster'] end end