Class: Resque::Cluster::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/resque/cluster/config.rb,
lib/resque/cluster/config/file.rb,
lib/resque/cluster/config/verifier.rb

Overview

Config is a global and local configuration of a member of a resque pool cluster

Defined Under Namespace

Classes: File, Verifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path, global_config_path = nil) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/resque/cluster/config.rb', line 10

def config
  @config
end

#configsObject (readonly)

Returns the value of attribute configs.



10
11
12
# File 'lib/resque/cluster/config.rb', line 10

def configs
  @configs
end

#global_configObject (readonly)

Returns the value of attribute global_config.



10
11
12
# File 'lib/resque/cluster/config.rb', line 10

def global_config
  @global_config
end

#verifierObject (readonly)

Returns the value of attribute verifier.



10
11
12
# File 'lib/resque/cluster/config.rb', line 10

def verifier
  @verifier
end

Instance Method Details

#errorsObject



51
52
53
# File 'lib/resque/cluster/config.rb', line 51

def errors
  @errors + configs.map { |config| config.errors.map { |error| "#{config}: #{error}" } }.flatten
end

#gru_formatObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/resque/cluster/config.rb', line 35

def gru_format
  return {} unless verified?

  {
    manage_worker_heartbeats: true,
    host_maximums:            host_maximums,
    client_settings:          Resque.redis.client.options,
    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_errorsObject



65
66
67
68
69
# File 'lib/resque/cluster/config.rb', line 65

def log_errors
  errors.each do |error|
    puts error
  end
end

#log_warningsObject



59
60
61
62
63
# File 'lib/resque/cluster/config.rb', line 59

def log_warnings
  warnings.each do |warning|
    puts warning
  end
end

#verified?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/resque/cluster/config.rb', line 31

def verified?
  verifier.verified? && complete_worker_config?
end

#warningsObject



55
56
57
# File 'lib/resque/cluster/config.rb', line 55

def warnings
  @warnings ||= []
end