Module: Appfuel::Service::Config

Defined in:
lib/appfuel/service/config/aws.rb,
lib/appfuel/service/config/sentry.rb,
lib/appfuel/service/config/worker.rb,
lib/appfuel/service/config/database.rb,
lib/appfuel/service/config/newrelic.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-west-2'

    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

.db_definitionObject

Defines database configuration. This is designed to hold more than one database connection which is why they are named invidually. We are using active record so the config is taylored to that style connection.

Configuration Overview

pool: Managed connection which controls the amount of thread access to

a limited number of database connections

adapter: We always use postgres, rarely changes encoding: We always use unicode, rarely changes database Name of the database username Name of the database user password Database password host Location of the database server

Returns:

  • Defintion



20
21
22
23
24
25
26
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
# File 'lib/appfuel/service/config/database.rb', line 20

def self.db_definition
  Appfuel::Configuration.define :db do
    validator {
      required(:main).filled(:hash?)
      required(:path).filled(:str?)
      required(:seed_path).filled(:str?)
      required(:migrations_path).filled(:str?)
    }

    db_path = 'db'
    defaults path: db_path,
      migrations_path: "#{db_path}/migrations",
      seed_path: 'db/seed'

    define :main do
      defaults pool:     5,
        adapter: 'postgresql',
        encoding: 'unicode',
        schema_format: 'sql'

      validator do
        required(:schema_search_path).filled(:str?)
        required(:schema_format).filled(:str?)
        required(:database).filled(:str?)
        required(:username).filled(:str?)
        required(:password).filled(:str?)
        required(:host).filled(:str?)
        required(:adapter).filled(:str?)
        optional(:pool).filled(:int?)
        optional(:encoding).filled(:str?)
        optional(:port).filled(:int?)
      end
    end
  end
end

.newrelic_definitionObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/appfuel/service/config/newrelic.rb', line 4

def self.newrelic_definition
  Appfuel::Configuration.define :newrelic do
    defaults license_key: '',
             app_name: '',
             log_level: 'info',
             monitor_mode: 'true',
             agent_enabled:'true'
    validator {
      required(:new_relic_license_key).filled(:str?)
      required(:new_relic_app_name).filled(:str?)
      required(:new_relic_log_level).filled(:str?)
      required(:new_relic_monitor_mode).filled(:str?)
      required(:new_relic_agent_enabled).filled(:str?)
    }
  end
end

.sentry_definitionObject



4
5
6
7
8
9
10
# File 'lib/appfuel/service/config/sentry.rb', line 4

def self.sentry_definition
  Appfuel::Configuration.define :sentry do
    validator {
       required(:dsn).filled(:str?)
    }
  end
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
# File 'lib/appfuel/service/config/sneakers.rb', line 27

def self.sneakers_definition
  Appfuel::Configuration.define :sneakers do
    defaults heartbeat: 60,
            ack: true,
            daemonize: true,
            workers: 1,
            threads: 1,
            prefetch: 1,
            timeout_job_after: 5,
            durable: true

    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(:log).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

.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
43
44
45
46
# File 'lib/appfuel/service/config/worker.rb', line 20

def self.worker_definition
  Appfuel::Configuration.define :worker do
    file 'config/app.yaml'
    defaults logfile: 'stdout',
              audit_logfile: 'stdout'

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