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
30
# 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)
  @version_git_hash = config_version
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

#version_git_hashObject (readonly)

Returns the value of attribute version_git_hash.



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

def version_git_hash
  @version_git_hash
end

Instance Method Details

#errorsObject



53
54
55
# File 'lib/resque/cluster/config.rb', line 53

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

#gru_formatObject



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

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,
    version_hash:             version_git_hash
  }
end

#log_errorsObject



67
68
69
70
71
# File 'lib/resque/cluster/config.rb', line 67

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

#log_warningsObject



61
62
63
64
65
# File 'lib/resque/cluster/config.rb', line 61

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

#verified?Boolean

Returns:

  • (Boolean)


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

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

#warningsObject



57
58
59
# File 'lib/resque/cluster/config.rb', line 57

def warnings
  @warnings ||= []
end