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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d89625ae0ff9e49ecd85a326aec3467a84d91bb
4
- data.tar.gz: 910682f71f8d186de81227cd6a77026ef9793732
3
+ metadata.gz: 61149209ac903dc3cae423f04a741c76fea1ae48
4
+ data.tar.gz: e81f73fb4a7bcd86f9b286eab347564d1e1de736
5
5
  SHA512:
6
- metadata.gz: 358fa56770a955568a92c697233f5e5c899eb6f2acabee45569940a12d97c1a2e981986dddf9e4780e6072a51e9ead2d85df3a30b6702a5268830d540d51e85d
7
- data.tar.gz: 2189021627302cab3ed90a64cd2ddcddf40204fd03384e5c7ad6ecb6a59a09bfb43ac4fc3d87b30a8e6401f1b861eced2e3713977c8c838d52399c7771402baf
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
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in appfuel-service.gemspec
4
4
  gemspec
5
5
 
6
- #gem 'appfuel', path: '../appfuel'
6
+ #gem 'appfuel', path:'../appfuel'
7
7
 
8
8
  group :test do
9
9
  gem "simplecov", "~> 0.14"
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
 
@@ -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.7"
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 license_key: '',
7
- app_name: '',
8
- log_level: 'info',
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(:new_relic_license_key).filled(:str?)
13
- required(:new_relic_app_name).filled(:str?)
14
- required(:new_relic_log_level).filled(:str?)
15
- required(:new_relic_monitor_mode).filled(:str?)
16
- required(:new_relic_agent_enabled).filled(:str?)
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
@@ -28,6 +28,8 @@ module Appfuel
28
28
  Appfuel::Configuration.define :sneakers do
29
29
  defaults heartbeat: 60,
30
30
  ack: true,
31
+ pid_path: 'tmp/sneakers.pid',
32
+ log: 'tmp/log/sneakers.log',
31
33
  daemonize: true,
32
34
  workers: 1,
33
35
  threads: 1,
@@ -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
- optional(:sneakers).filled(:hash?)
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.aws_definition,
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
@@ -0,0 +1,4 @@
1
+ Appfuel::Initialize.define('global.worker') do |config, container|
2
+
3
+
4
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'initializers/worker'
2
+ require_relative 'initializers/logging'
3
+ require_relative 'initializers/message_broker'
4
+ require_relative 'initializers/db'
@@ -1,5 +1,5 @@
1
1
  module Appfuel
2
2
  module Service
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
@@ -7,7 +7,22 @@ module Appfuel
7
7
 
8
8
  class << self
9
9
  def inherited(klass)
10
- stage_class_for_registration(klass)
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.3
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-07 00:00:00.000000000 Z
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.7
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.7
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