appfuel-service 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/Gemfile +1 -1
- data/README.md +2 -31
- data/appfuel-service.gemspec +1 -1
- data/lib/appfuel/service/config/newrelic.rb +8 -10
- data/lib/appfuel/service/config/sneakers.rb +2 -0
- data/lib/appfuel/service/config/worker.rb +2 -8
- data/lib/appfuel/service/config.rb +72 -0
- data/lib/appfuel/service/initializers/db.rb +21 -0
- data/lib/appfuel/service/initializers/logging.rb +27 -0
- data/lib/appfuel/service/initializers/message_broker.rb +25 -0
- data/lib/appfuel/service/initializers/worker.rb +4 -0
- data/lib/appfuel/service/initializers.rb +4 -0
- data/lib/appfuel/service/version.rb +1 -1
- data/lib/appfuel/service/worker.rb +16 -1
- metadata +9 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61149209ac903dc3cae423f04a741c76fea1ae48
|
4
|
+
data.tar.gz: e81f73fb4a7bcd86f9b286eab347564d1e1de736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee88a0fad46adbdd86e00cd121cddd2a65ba74d2e49f93a6f2b63086c5bcbc4b8d3292b484a859174328c6977a850a6e220afee4e45bef99f51558b0c1abff13
|
7
|
+
data.tar.gz: 4870fa74f0eeb0e45361db359dc5b765ad8cdec6d30d50592e534b0ca2cd87fae8faceba0454ce883c5191cfb22c86a5e5fbda475f056f56015c2b468ad7084e
|
data/CHANGELOG.md
CHANGED
@@ -3,8 +3,14 @@ All notable changes to this project will be documented in this file. (Pending ap
|
|
3
3
|
|
4
4
|
# [Unreleased]
|
5
5
|
|
6
|
+
|
6
7
|
# Releases
|
8
|
+
## [[0.1.4]](https://github.com/rsb/appfuel/releases/tag/0.1.3) 2017-06-14
|
9
|
+
### Added
|
10
|
+
- Initialzers for worker and db
|
7
11
|
|
8
12
|
## [[0.1.3]](https://github.com/rsb/appfuel/releases/tag/0.1.3) 2017-06-07
|
9
13
|
### Added
|
10
14
|
- Configuration definitions for database, aws, worker, sentry and new relic
|
15
|
+
### Added
|
16
|
+
- Method in Config.rb such that it overrides the default implimentation.Also added test case fro Config.rb.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,36 +1,7 @@
|
|
1
|
-
[![Build
|
2
|
-
Status](https://travis-ci.org/rsb/appfuel-service.svg?branch=master)](https://travis-ci.org/rsb/appfuel-service)
|
1
|
+
[![Travis Build Status](https://travis-ci.org/rsb/appfuel-service.svg?branch=master)](https://travis-ci.org/rsb/appfuel-service)
|
3
2
|
# Appfuel::Service
|
3
|
+
A `microservice` pattern using `Appfuel` with a [Sneaker's](http://jondot.github.io/sneakers/) and [RabbitMQ](https://www.rabbitmq.com/)
|
4
4
|
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/appfuel/service`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
-
|
7
|
-
TODO: Delete this and the text above, and describe your gem
|
8
|
-
|
9
|
-
## Installation
|
10
|
-
|
11
|
-
Add this line to your application's Gemfile:
|
12
|
-
|
13
|
-
```ruby
|
14
|
-
gem 'appfuel-service'
|
15
|
-
```
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install appfuel-service
|
24
|
-
|
25
|
-
## Usage
|
26
|
-
|
27
|
-
TODO: Write usage instructions here
|
28
|
-
|
29
|
-
## Development
|
30
|
-
|
31
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
32
|
-
|
33
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
34
5
|
|
35
6
|
## Contributing
|
36
7
|
|
data/appfuel-service.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "appfuel", "~> 0.2
|
23
|
+
spec.add_dependency "appfuel", "~> 0.2"
|
24
24
|
spec.add_dependency "sneakers", "~> 2.5"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
@@ -3,17 +3,15 @@ module Appfuel
|
|
3
3
|
module Config
|
4
4
|
def self.newrelic_definition
|
5
5
|
Appfuel::Configuration.define :newrelic do
|
6
|
-
defaults
|
7
|
-
|
8
|
-
|
9
|
-
monitor_mode: 'true',
|
10
|
-
agent_enabled:'true'
|
6
|
+
defaults log_level: 'info',
|
7
|
+
monitor_mode: 'true',
|
8
|
+
agent_enabled: 'true'
|
11
9
|
validator {
|
12
|
-
required(:
|
13
|
-
required(:
|
14
|
-
|
15
|
-
|
16
|
-
|
10
|
+
required(:license_key).filled(:str?)
|
11
|
+
required(:app_name).filled(:str?)
|
12
|
+
optional(:log_level).filled(:str?)
|
13
|
+
optional(:monitor_mode).filled(:str?)
|
14
|
+
optional(:agent_enabled).filled(:str?)
|
17
15
|
}
|
18
16
|
end
|
19
17
|
end
|
@@ -30,17 +30,11 @@ module Appfuel
|
|
30
30
|
# Children will be validated on there own
|
31
31
|
# we are just ensuring they exist
|
32
32
|
required(:db).filled(:hash?)
|
33
|
-
|
34
|
-
optional(:aws).filled(:hash?)
|
35
|
-
optional(:sentry).filled(:hash?)
|
36
|
-
optional(:newrelic).filled(:hash?)
|
33
|
+
required(:sneakers).filled(:hash?)
|
37
34
|
}
|
38
35
|
self << [
|
39
|
-
Config.db_definition,
|
40
36
|
Config.sneakers_definition,
|
41
|
-
Config.
|
42
|
-
Config.sentry_definition,
|
43
|
-
Config.newrelic_definition
|
37
|
+
Config.db_definition,
|
44
38
|
]
|
45
39
|
end
|
46
40
|
end
|
@@ -5,3 +5,75 @@ require_relative 'config/aws'
|
|
5
5
|
require_relative 'config/worker'
|
6
6
|
require_relative 'config/sentry'
|
7
7
|
require_relative 'config/newrelic'
|
8
|
+
|
9
|
+
module Appfuel
|
10
|
+
module Service
|
11
|
+
module Config
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
# Returns the worker definition while allowing you to override it and
|
16
|
+
# its child definition values through the options hash
|
17
|
+
#
|
18
|
+
# @param options [Hash]
|
19
|
+
# @return Appfuel::Configuration::DefinitionDsl
|
20
|
+
def definition(options = {})
|
21
|
+
definition = options.delete(:definition) || worker_definition
|
22
|
+
update_definition(definition, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update_definition(definition, options)
|
26
|
+
options = validate_hash!(options)
|
27
|
+
return definition if options.empty?
|
28
|
+
|
29
|
+
[:defaults, :file, :env, :exclude, :children].each do |type|
|
30
|
+
name = "definition_#{type}"
|
31
|
+
send(name, definition, options[type]) if options.key?(type)
|
32
|
+
end
|
33
|
+
|
34
|
+
definition
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def definition_file(definition, file)
|
40
|
+
definition.file(file)
|
41
|
+
end
|
42
|
+
|
43
|
+
def definition_defaults(definition, defaults)
|
44
|
+
defaults = validate_hash!(defaults, :defaults)
|
45
|
+
definition.defaults(definition.defaults.merge(defaults))
|
46
|
+
end
|
47
|
+
|
48
|
+
def definition_env(definition, env)
|
49
|
+
env = validate_hash!(options[:env], :env)
|
50
|
+
definition.env(definition.env.merge(env))
|
51
|
+
end
|
52
|
+
|
53
|
+
def definition_exclude(definition, excludes)
|
54
|
+
if excludes.is_a?(String) || excludes.is_a?(Symbol)
|
55
|
+
excludes = [exlcudes]
|
56
|
+
end
|
57
|
+
Fail "Options (excludes) must be an array" unless excludes.is_a?(Array)
|
58
|
+
|
59
|
+
excludes.each do |item|
|
60
|
+
definition.delete(item)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def definition_children(definition, children)
|
65
|
+
validate_hash!(children, :children).each do |key, options|
|
66
|
+
update_definition(definition[key], options)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate_hash!(value, key = nil)
|
71
|
+
msg = "Options"
|
72
|
+
msg << " (#{key})" unless key.nil?
|
73
|
+
fail "#{msg} must be a hash" unless value.is_a?(Hash)
|
74
|
+
value
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Appfuel::Initialize.define('global.db') do |config, container|
|
2
|
+
fail "[initializer db] :db config not found" unless config.key?(:db)
|
3
|
+
fail "[initializer db] :main not found in :db" unless config[:db].key?(:main)
|
4
|
+
|
5
|
+
require 'pg'
|
6
|
+
require 'active_record'
|
7
|
+
config[:db][:main] = config[:db][:main].with_indifferent_access
|
8
|
+
|
9
|
+
ActiveSupport.on_load(:active_record) do
|
10
|
+
if ActiveRecord::Base.connected?
|
11
|
+
ActiveRecord::Base.connection_pool.disconnect!
|
12
|
+
end
|
13
|
+
|
14
|
+
if container.key?(:logger)
|
15
|
+
ActiveRecord::Base.logger = container[:logger]
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveRecord::Base.establish_connection(config[:db][:main])
|
19
|
+
end
|
20
|
+
nil
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Appfuel::Initialize.define('global.logging') do |config, container|
|
2
|
+
logfile = config[:logfile] || 'stdout'
|
3
|
+
logger_file = ->(file) {
|
4
|
+
file = file.to_s
|
5
|
+
if file.empty? || file.downcase == 'stdout'
|
6
|
+
file = $stdout
|
7
|
+
elsif file.downcase == 'stderr'
|
8
|
+
file = $stderr
|
9
|
+
else
|
10
|
+
file
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
factory = ->(file, level = 'info', file_coercer = logger_file) {
|
15
|
+
logger = Logger.new(file_coercer.call(file))
|
16
|
+
if level
|
17
|
+
logger.level = Logger.const_get(level.to_s.upcase)
|
18
|
+
end
|
19
|
+
|
20
|
+
logger.formatter = Sneakers::Support::ProductionFormatter
|
21
|
+
logger
|
22
|
+
}
|
23
|
+
|
24
|
+
container.register(:logger, factory.call(logfile))
|
25
|
+
container.register(:logger_factory, factory)
|
26
|
+
nil
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
Appfuel::Initialize.define('global.message_broker') do |config, container|
|
2
|
+
unless config.key?(:sneakers)
|
3
|
+
fail "[initializer message_broker] :sneakers not found"
|
4
|
+
end
|
5
|
+
|
6
|
+
consumer_keys = container['message_brokers.consumer_keys']
|
7
|
+
unless consumer_keys.is_a?(Array)
|
8
|
+
fail "[initializer message_broker] message_borker.consumers must be " +
|
9
|
+
" an Array"
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'sneakers'
|
13
|
+
require 'sneakers/runner'
|
14
|
+
|
15
|
+
Sneakers.configure(config[:sneakers])
|
16
|
+
|
17
|
+
|
18
|
+
consumers = consumer_keys.each.inject([]) do |result, key|
|
19
|
+
result << container[key]
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
container.register("message_brokers.runner", Sneakers::Runner.new(consumers))
|
24
|
+
nil
|
25
|
+
end
|
@@ -7,7 +7,22 @@ module Appfuel
|
|
7
7
|
|
8
8
|
class << self
|
9
9
|
def inherited(klass)
|
10
|
-
|
10
|
+
container = klass.app_container
|
11
|
+
consumer_key = "#{klass.top_container_key}.consumer_keys"
|
12
|
+
unless container.key?(consumer_key)
|
13
|
+
container.register(consumer_key, [])
|
14
|
+
end
|
15
|
+
key = klass.container_class_path
|
16
|
+
container.register(key, klass)
|
17
|
+
container[consumer_key] << key
|
18
|
+
end
|
19
|
+
|
20
|
+
def top_container_key
|
21
|
+
"message_brokers"
|
22
|
+
end
|
23
|
+
|
24
|
+
def container_class_type
|
25
|
+
'consumers'
|
11
26
|
end
|
12
27
|
end
|
13
28
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appfuel-service
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Scott-Buccleuch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appfuel
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.2
|
19
|
+
version: '0.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.2
|
26
|
+
version: '0.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sneakers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,6 +107,11 @@ files:
|
|
107
107
|
- lib/appfuel/service/config/sentry.rb
|
108
108
|
- lib/appfuel/service/config/sneakers.rb
|
109
109
|
- lib/appfuel/service/config/worker.rb
|
110
|
+
- lib/appfuel/service/initializers.rb
|
111
|
+
- lib/appfuel/service/initializers/db.rb
|
112
|
+
- lib/appfuel/service/initializers/logging.rb
|
113
|
+
- lib/appfuel/service/initializers/message_broker.rb
|
114
|
+
- lib/appfuel/service/initializers/worker.rb
|
110
115
|
- lib/appfuel/service/msg_request.rb
|
111
116
|
- lib/appfuel/service/version.rb
|
112
117
|
- lib/appfuel/service/worker.rb
|