module Appfuel::Service::Config

Public Class Methods

aws_definition() click to toggle source

Defines how to parse and validate configuration data for aws

Configuration Overview:

access_key_id:    access credentials for aws
secret_access_key: access credentials for aws
assets_bucket:    name of bucket to hold assets
documents_buckets  name of bucket to hold documents

@returns Config::Definition
# File lib/appfuel/service/config/aws.rb, line 14
def self.aws_definition
  Appfuel::Configuration.define :aws do
    defaults region: 'us-east-1'

    validator {
      required(:region).filled(:str?)
      optional(:access_key_id).filled(:str?)
      optional(:secret_access_key).filled(:str?)
      optional(:kms_master_key_id).filled(:str?)
      optional(:kms_data_key_cipher).filled(:str?)
    }
  end
end
definition(options = {}) click to toggle source

Returns the worker definition while allowing you to override it and its child definition values through the options hash

@param options [Hash] @return Appfuel::Configuration::DefinitionDsl

# File lib/appfuel/service/config.rb, line 16
def definition(options = {})
  definition = options.delete(:definition) || worker_definition
  update_definition(definition, options)
end
sneakers_definition() click to toggle source

Defines how to parse and validate configuration data for sneakers for more information of the configuration please go to the wiki for the sneakers project github.com/jondot/sneakers/wiki/Configuration

Configuration Overview:

heartbeat:         RabbitMQ   heartbeat delay in seconds
ack:               RabbitMQ   the worker must acknowledge work is done
daemonize:         Sneakers   deameonize the worker
log                Sneakers   log file location
pid_path           Sneakers   daemon's pidfile location
workers            Sneakers   the number of worker processes
threads            Sneakers   number of threads per worker
prefetch           RabbitMQ   how many messages to send to a worker
timeout_job_after  Sneakers   Maximal seconds to wait for job
start_worker_delay Sneakers   Delay between thread startup
durable            RabbitMQ   Queue should persist
exchange           RabbitMQ   name of the exchange
exchange_type      RabbitMQ   type of exchange (direct, topic, fanout)
vhost              RabbitMQ   name of the vhost
amqp               RabbitMQ   connection string used to communicate

@returns Config::Definition
# File lib/appfuel/service/config/sneakers.rb, line 27
def self.sneakers_definition
  Appfuel::Config.define :sneakers do
    defaults heartbeat: 60,
            ack: true,
            pid_path: 'tmp/pids/sneakers.pid',
            logfile: 'tmp/log/sneakers.log',
            daemonize: true,
            workers: 1,
            threads: 1,
            prefetch: 1,
            retry_timeout: 60 * 1000, # 60s
            timeout_job_after: 5,
            durable: true

    env RABBITMQ_URL: :amqp

    validator {
      required(:amqp).filled(:str?)
      required(:vhost).filled(:str?)
      required(:exchange).filled(:str?)
      required(:exchange_type).filled(:str?)
      required(:durable).filled(:bool?)
      required(:ack).filled(:bool?)
      required(:daemonize).filled(:bool?)
      required(:heartbeat).filled(:int?)
      required(:logfile).filled(:str?)
      required(:pid_path).filled(:str?)
      required(:threads).filled(:int?)
      required(:workers).filled(:int?)
      required(:timeout_job_after).filled(:int?)
      required(:prefetch).filled(:int?)
    }
  end
end
update_definition(definition, options) click to toggle source
# File lib/appfuel/service/config.rb, line 21
def update_definition(definition, options)
  options = validate_hash!(options)
  return definition if options.empty?

  [:defaults, :file, :env, :exclude, :children].each do |type|
    name = "definition_#{type}"
    send(name, definition, options[type]) if options.key?(type)
  end

  definition
end
worker_definition() click to toggle source

Defines the configuration for the whole worker. It basically has two child definitions :db and :sneakers

Configuration Overview

env: The environement this worker is deployed as dev, qa, stg, prod logfile: The location of the application log file if the value is

stdout or stderr it will use that instead

dispatchers List of workers that dispatch messages to actions. The reason

why you would want more than one is to use different exchange
types

db Database configuration please see sp_offers/config/database sneakers RabbitMQ configuration please see sp_offers/config/sneakers aws Configuration S3 where we store our documents @return Definition

# File lib/appfuel/service/config/worker.rb, line 20
def self.worker_definition
  Appfuel::Config.define :worker do
    file 'config/app.yaml'
    defaults log_file:       'stdout',
              log_level:     'info',
              audit_logfile: 'stdout'

    validator {
      required(:env).filled(:str?)
      required(:log_file).filled(:str?)
      required(:log_level).filled(:str?)
      required(:audit_logfile).filled(:str?)
      # Children will be validated on there own
      # we are just ensuring they exist
      optional(:db).filled(:hash?)
      required(:sneakers).filled(:hash?)
    }
    self << [
      Config.sneakers_definition,
      Appfuel::Config.db_definition,
    ]
  end
end

Private Class Methods

definition_children(definition, children) click to toggle source
# File lib/appfuel/service/config.rb, line 60
def definition_children(definition, children)
  validate_hash!(children, :children).each do |key, options|
    update_definition(definition[key], options)
  end
end
definition_defaults(definition, defaults) click to toggle source
# File lib/appfuel/service/config.rb, line 39
def definition_defaults(definition, defaults)
  defaults = validate_hash!(defaults, :defaults)
  definition.defaults(definition.defaults.merge(defaults))
end
definition_env(definition, env) click to toggle source
# File lib/appfuel/service/config.rb, line 44
def definition_env(definition, env)
  env = validate_hash!(options[:env], :env)
  definition.env(definition.env.merge(env))
end
definition_exclude(definition, excludes) click to toggle source
# File lib/appfuel/service/config.rb, line 49
def definition_exclude(definition, excludes)
  if excludes.is_a?(String) || excludes.is_a?(Symbol)
    excludes = [exlcudes]
  end
  Fail "Options (excludes) must be an array" unless excludes.is_a?(Array)

  excludes.each do |item|
    definition.delete(item)
  end
end
definition_file(definition, file) click to toggle source
# File lib/appfuel/service/config.rb, line 35
def definition_file(definition, file)
  definition.file(file)
end
validate_hash!(value, key = nil) click to toggle source
# File lib/appfuel/service/config.rb, line 66
def validate_hash!(value, key =  nil)
  msg = "Options"
  msg << " (#{key})" unless key.nil?
  fail "#{msg} must be a hash" unless value.is_a?(Hash)
  value
end