Module: Appfuel::Service::Config

Defined in:
lib/appfuel/service/config.rb,
lib/appfuel/service/config/aws.rb,
lib/appfuel/service/config/worker.rb,
lib/appfuel/service/config/sneakers.rb

Class Method Summary collapse

Class Method Details

.aws_definitionObject

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


14
15
16
17
18
19
20
21
22
23
24
25
26
# 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 = {}) ⇒ Object

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

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • Appfuel::Configuration::DefinitionDsl



16
17
18
19
# File 'lib/appfuel/service/config.rb', line 16

def definition(options = {})
  definition = options.delete(:definition) || worker_definition
  update_definition(definition, options)
end

.sneakers_definitionObject

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


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# 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_definitionObject

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

Returns:

  • Definition



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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