class ResqueToCloudwatch::Config

Attributes

access_key_id[R]
enable_graphite[R]
graphite_host[R]
graphite_port[R]
hostname[R]
namespace[R]
period[R]
project[R]
redis_host[R]
redis_port[R]
region[R]
secret_access_key[R]

Public Class Methods

new(path) click to toggle source
# File lib/resque_to_cloudwatch/config.rb, line 12
def initialize(path)
  $log.info "Loading configuration"
  raise "Config file #{path} not found or readable" unless File.exists?(path)
  @required_opts = %w{access_key_id secret_access_key project period region redis_host redis_port namespace}
  @hash = YAML.load_file(path)
  raise "Config file #{path} is empty" unless @hash
  validate_config
  @hash.each_pair do |opt,value|
    # Support old-style where region is not an array
    if opt == 'region' && value.is_a?(String)
      value = [value]
    end
    instance_variable_set("@#{opt}", value)
    $log.info "Config parameter: #{opt} is #{value}"
  end
  
  # Set up AWS credentials
  AWS.config(
    :access_key_id => @hash['access_key_id'],
    :secret_access_key => @hash['secret_access_key']
  )
end

Private Instance Methods

validate_config() click to toggle source
# File lib/resque_to_cloudwatch/config.rb, line 37
def validate_config
  missing_opts = @required_opts.select do |opt|
    @hash[opt].nil?
  end
  raise "Missing options: #{missing_opts.join(", ")}" unless missing_opts.empty?
  if @hash["enable_graphite"]
    raise "Graphite enabled but config missing graphite_host" if @hash["graphite_host"].nil?
    @hash["graphite_port"] ||= 2003
  else
    @hash["enable_graphite"] = false
  end
end