appfuel-service 0.1.7 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/appfuel-service.gemspec +1 -1
- data/lib/appfuel/service/config/sneakers.rb +1 -1
- data/lib/appfuel/service/config/worker.rb +6 -4
- data/lib/appfuel/service/config.rb +0 -4
- data/lib/appfuel/service/initializers/all.rb +2 -0
- data/lib/appfuel/service/initializers/message_broker.rb +4 -10
- data/lib/appfuel/service/rpc_client.rb +57 -0
- data/lib/appfuel/service/version.rb +1 -1
- data/lib/appfuel/service.rb +1 -0
- metadata +6 -10
- data/lib/appfuel/service/config/database.rb +0 -57
- data/lib/appfuel/service/config/newrelic.rb +0 -20
- data/lib/appfuel/service/config/sentry.rb +0 -13
- data/lib/appfuel/service/initializers/db.rb +0 -21
- data/lib/appfuel/service/initializers/logging.rb +0 -27
- data/lib/appfuel/service/initializers.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3c22097e153fb04fdb6960de41250197d35b497
|
4
|
+
data.tar.gz: f5ff621f80b073bef84cc4e22f530bc8fec3d7e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e3deed6e71ad5616e66e2bdfc105a1068ea2b2c357cb705ac9de6a3fe3db7e1954163a9dc16638ea0d145c07f651cdae8af97a49bdfaa5889822c62b87428d9
|
7
|
+
data.tar.gz: 5d12e7a068976c4a2ef8b30064d0e619be0426ddb67d1a2ed7a97da622575e281d4a2e1195f465740f5bd56e1859a9c18b4de51a932fb8e63b0e4d9002009219
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file. (Pending ap
|
|
5
5
|
|
6
6
|
|
7
7
|
# Releases
|
8
|
+
## [[0.2.1]](https://github.com/rsb/appfuel/releases/tag/0.2.8) 2017-06-28
|
9
|
+
### Fixed
|
10
|
+
- fixed initializer for message broker to allow cli to start up individual
|
11
|
+
queues
|
12
|
+
|
13
|
+
## [[0.2.0]](https://github.com/rsb/appfuel/releases/tag/0.2.0) 2017-06-21
|
14
|
+
### Added
|
15
|
+
- added rpc client to publish rabbitmq messages
|
16
|
+
|
8
17
|
## [[0.1.7]](https://github.com/rsb/appfuel/releases/tag/0.1.7) 2017-06-20
|
9
18
|
### Changed
|
10
19
|
- `upgraded` `appfuel` to 0.3.0
|
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.
|
23
|
+
spec.add_dependency "appfuel", "~> 0.4"
|
24
24
|
spec.add_dependency "sneakers", "~> 2.5"
|
25
25
|
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.15"
|
@@ -18,14 +18,16 @@ module Appfuel
|
|
18
18
|
# aws Configuration S3 where we store our documents
|
19
19
|
# @return Definition
|
20
20
|
def self.worker_definition
|
21
|
-
Appfuel::
|
21
|
+
Appfuel::Config.define :worker do
|
22
22
|
file 'config/app.yaml'
|
23
|
-
defaults
|
23
|
+
defaults log_file: 'stdout',
|
24
|
+
log_level: 'info',
|
24
25
|
audit_logfile: 'stdout'
|
25
26
|
|
26
27
|
validator {
|
27
28
|
required(:env).filled(:str?)
|
28
|
-
required(:
|
29
|
+
required(:log_file).filled(:str?)
|
30
|
+
required(:log_level).filled(:str?)
|
29
31
|
required(:audit_logfile).filled(:str?)
|
30
32
|
# Children will be validated on there own
|
31
33
|
# we are just ensuring they exist
|
@@ -34,7 +36,7 @@ module Appfuel
|
|
34
36
|
}
|
35
37
|
self << [
|
36
38
|
Config.sneakers_definition,
|
37
|
-
Config.db_definition,
|
39
|
+
Appfuel::Config.db_definition,
|
38
40
|
]
|
39
41
|
end
|
40
42
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
require 'yaml'
|
2
|
-
require_relative 'config/database'
|
3
2
|
require_relative 'config/sneakers'
|
4
|
-
require_relative 'config/aws'
|
5
3
|
require_relative 'config/worker'
|
6
|
-
require_relative 'config/sentry'
|
7
|
-
require_relative 'config/newrelic'
|
8
4
|
|
9
5
|
module Appfuel
|
10
6
|
module Service
|
@@ -3,10 +3,9 @@ Appfuel::Initialize.define('global.message_broker') do |config, container|
|
|
3
3
|
fail "[initializer message_broker] :sneakers not found"
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
" an Array"
|
6
|
+
unless container['message_brokers.consumer_keys'].is_a?(Array)
|
7
|
+
fail "[initializer message_broker] message_borker.consumer_keys " +
|
8
|
+
"must be an Array"
|
10
9
|
end
|
11
10
|
|
12
11
|
require 'sneakers'
|
@@ -15,11 +14,6 @@ Appfuel::Initialize.define('global.message_broker') do |config, container|
|
|
15
14
|
Sneakers.configure(config[:sneakers])
|
16
15
|
|
17
16
|
|
18
|
-
|
19
|
-
result << container[key]
|
20
|
-
result
|
21
|
-
end
|
22
|
-
|
23
|
-
container.register("message_brokers.runner", Sneakers::Runner.new(consumers))
|
17
|
+
container.register("message_brokers.runner_class", Sneakers::Runner)
|
24
18
|
nil
|
25
19
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Appfuel
|
2
|
+
module Service
|
3
|
+
class RpcClient < Sneakers::Publisher
|
4
|
+
attr_accessor :call_id, :response
|
5
|
+
attr_reader :channel, :config, :exchange, :reply_queue, :lock, :condition
|
6
|
+
|
7
|
+
def publish(to_queue, action_route, msg, headers = {})
|
8
|
+
@mutex.synchronize do
|
9
|
+
ensure_connection! unless connected?
|
10
|
+
end
|
11
|
+
|
12
|
+
self.call_id = SecureRandom.uuid
|
13
|
+
msg = msg.to_json
|
14
|
+
@response = nil
|
15
|
+
params = {
|
16
|
+
routing_key: to_queue,
|
17
|
+
correlation_id: call_id,
|
18
|
+
reply_to: reply_queue.name,
|
19
|
+
content_type: 'application/json',
|
20
|
+
headers: {action_route: action_route}.merge(headers)
|
21
|
+
}
|
22
|
+
|
23
|
+
exchange.publish(msg, params)
|
24
|
+
lock.synchronize { condition.wait(lock) }
|
25
|
+
|
26
|
+
result = JSON.parse(@response)
|
27
|
+
Appfuel::ResponseHandler.new.create_response(result)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def ensure_connection!
|
33
|
+
super
|
34
|
+
@reply_queue = channel.queue('', exclusive: true)
|
35
|
+
subscribe
|
36
|
+
end
|
37
|
+
|
38
|
+
def subscribe
|
39
|
+
@lock = Mutex.new
|
40
|
+
@condition = ConditionVariable.new
|
41
|
+
that = self
|
42
|
+
|
43
|
+
reply_queue.bind(@opts[:exchange], routing_key: reply_queue.name)
|
44
|
+
|
45
|
+
reply_queue.subscribe do |_delivery_info, properties, payload|
|
46
|
+
if properties[:correlation_id] == that.call_id
|
47
|
+
that.response = payload.to_s
|
48
|
+
that.lock.synchronize { that.condition.signal }
|
49
|
+
else
|
50
|
+
Sneakers.logger.warn "request not found for correlation_id: " +
|
51
|
+
"(#{properties[:correlation_id]}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/appfuel/service.rb
CHANGED
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.2.1
|
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-28 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.
|
19
|
+
version: '0.4'
|
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.
|
26
|
+
version: '0.4'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sneakers
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,17 +102,13 @@ files:
|
|
102
102
|
- lib/appfuel/service.rb
|
103
103
|
- lib/appfuel/service/config.rb
|
104
104
|
- lib/appfuel/service/config/aws.rb
|
105
|
-
- lib/appfuel/service/config/database.rb
|
106
|
-
- lib/appfuel/service/config/newrelic.rb
|
107
|
-
- lib/appfuel/service/config/sentry.rb
|
108
105
|
- lib/appfuel/service/config/sneakers.rb
|
109
106
|
- 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
|
107
|
+
- lib/appfuel/service/initializers/all.rb
|
113
108
|
- lib/appfuel/service/initializers/message_broker.rb
|
114
109
|
- lib/appfuel/service/initializers/worker.rb
|
115
110
|
- lib/appfuel/service/msg_request.rb
|
111
|
+
- lib/appfuel/service/rpc_client.rb
|
116
112
|
- lib/appfuel/service/version.rb
|
117
113
|
- lib/appfuel/service/worker.rb
|
118
114
|
homepage: https://github.com/rsb/appfuel-service
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Appfuel
|
2
|
-
module Service
|
3
|
-
module Config
|
4
|
-
# Defines database configuration. This is designed to hold more than one
|
5
|
-
# database connection which is why they are named invidually. We are using
|
6
|
-
# active record so the config is taylored to that style connection.
|
7
|
-
#
|
8
|
-
# Configuration Overview
|
9
|
-
#
|
10
|
-
# pool: Managed connection which controls the amount of thread access to
|
11
|
-
# a limited number of database connections
|
12
|
-
# adapter: We always use postgres, rarely changes
|
13
|
-
# encoding: We always use unicode, rarely changes
|
14
|
-
# database Name of the database
|
15
|
-
# username Name of the database user
|
16
|
-
# password Database password
|
17
|
-
# host Location of the database server
|
18
|
-
#
|
19
|
-
# @return Defintion
|
20
|
-
def self.db_definition
|
21
|
-
Appfuel::Configuration.define :db do
|
22
|
-
validator {
|
23
|
-
required(:main).filled(:hash?)
|
24
|
-
required(:path).filled(:str?)
|
25
|
-
required(:seed_path).filled(:str?)
|
26
|
-
required(:migrations_path).filled(:str?)
|
27
|
-
}
|
28
|
-
|
29
|
-
db_path = 'db'
|
30
|
-
defaults path: db_path,
|
31
|
-
migrations_path: "#{db_path}/migrations",
|
32
|
-
seed_path: 'db/seed'
|
33
|
-
|
34
|
-
define :main do
|
35
|
-
defaults pool: 5,
|
36
|
-
adapter: 'postgresql',
|
37
|
-
encoding: 'unicode',
|
38
|
-
schema_format: 'sql'
|
39
|
-
|
40
|
-
validator do
|
41
|
-
required(:schema_search_path).filled(:str?)
|
42
|
-
required(:schema_format).filled(:str?)
|
43
|
-
required(:database).filled(:str?)
|
44
|
-
required(:username).filled(:str?)
|
45
|
-
required(:password).filled(:str?)
|
46
|
-
required(:host).filled(:str?)
|
47
|
-
required(:adapter).filled(:str?)
|
48
|
-
optional(:pool).filled(:int?)
|
49
|
-
optional(:encoding).filled(:str?)
|
50
|
-
optional(:port).filled(:int?)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Appfuel
|
2
|
-
module Service
|
3
|
-
module Config
|
4
|
-
def self.newrelic_definition
|
5
|
-
Appfuel::Configuration.define :newrelic do
|
6
|
-
defaults log_level: 'info',
|
7
|
-
monitor_mode: 'true',
|
8
|
-
agent_enabled: 'true'
|
9
|
-
validator {
|
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?)
|
15
|
-
}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,21 +0,0 @@
|
|
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
|
@@ -1,27 +0,0 @@
|
|
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
|