roo_on_rails 1.10.0 → 1.11.0
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/.circleci/config.yml +672 -0
- data/.circleci/config.yml.erb +86 -0
- data/.gitignore +2 -1
- data/.rspec +2 -0
- data/CHANGELOG.md +27 -0
- data/README.md +75 -26
- data/README.routemaster_client.md +2 -0
- data/exe/roo_on_rails +96 -7
- data/lib/roo_on_rails/checks/base.rb +34 -17
- data/lib/roo_on_rails/checks/documentation/playbook.rb +2 -6
- data/lib/roo_on_rails/checks/environment.rb +2 -4
- data/lib/roo_on_rails/checks/environment_independent.rb +22 -0
- data/lib/roo_on_rails/checks/heroku/app_exists.rb +9 -2
- data/lib/roo_on_rails/checks/heroku/drains_metrics.rb +2 -2
- data/lib/roo_on_rails/checks/heroku/metrics_bridge_configured.rb +6 -2
- data/lib/roo_on_rails/checks/heroku/preboot_enabled.rb +3 -3
- data/lib/roo_on_rails/checks/papertrail/drain_exists.rb +4 -4
- data/lib/roo_on_rails/checks/papertrail/system_exists.rb +2 -2
- data/lib/roo_on_rails/checks/papertrail/system_named.rb +1 -1
- data/lib/roo_on_rails/checks/sidekiq/settings.rb +1 -1
- data/lib/roo_on_rails/checks/sidekiq/sidekiq.rb +1 -0
- data/lib/roo_on_rails/context_logging.rb +1 -0
- data/lib/roo_on_rails/harness.rb +8 -14
- data/lib/roo_on_rails/logfmt.rb +3 -15
- data/lib/roo_on_rails/logger.rb +104 -0
- data/lib/roo_on_rails/railties/database.rb +8 -6
- data/lib/roo_on_rails/railties/env.rb +11 -0
- data/lib/roo_on_rails/railties/google_oauth.rb +3 -7
- data/lib/roo_on_rails/railties/http.rb +31 -27
- data/lib/roo_on_rails/railties/logging.rb +16 -0
- data/lib/roo_on_rails/railties/new_relic.rb +15 -14
- data/lib/roo_on_rails/railties/rake_tasks.rb +0 -2
- data/lib/roo_on_rails/railties/routemaster.rb +9 -8
- data/lib/roo_on_rails/railties/sidekiq.rb +12 -8
- data/lib/roo_on_rails/routemaster/publisher.rb +14 -1
- data/lib/roo_on_rails/routemaster/publishers.rb +3 -3
- data/lib/roo_on_rails/sidekiq/process_scaling.rb +1 -1
- data/lib/roo_on_rails/tasks/db.rake +3 -2
- data/lib/roo_on_rails/version.rb +1 -1
- data/lib/roo_on_rails.rb +2 -1
- metadata +8 -7
- data/gemfiles/rails_3.gemfile.lock +0 -278
- data/gemfiles/rails_4.gemfile.lock +0 -293
- data/gemfiles/rails_5.gemfile.lock +0 -299
- data/gemfiles/rails_5_1.gemfile.lock +0 -300
- data/lib/roo_on_rails/railtie.rb +0 -16
@@ -22,20 +22,20 @@ module RooOnRails
|
|
22
22
|
requires LogDestinationExists
|
23
23
|
|
24
24
|
def intro
|
25
|
-
|
25
|
+
'Checking for Papertrail drain...'
|
26
26
|
end
|
27
27
|
|
28
28
|
def call
|
29
29
|
# find the PT drain
|
30
30
|
data = client.log_drain.list(app_name).
|
31
31
|
select { |h| h['url'] =~ /papertrailapp/ }
|
32
|
-
fail!
|
33
|
-
fail!
|
32
|
+
fail! "no Papertrail drain found on #{bold app_name}" if data.empty?
|
33
|
+
fail! "multiple Papertrail drains found on #{bold app_name}" if data.length > 1
|
34
34
|
|
35
35
|
data = data.first
|
36
36
|
fail! "app is draining to #{data['url']} instead of #{papertrail_url}" if data['url'] != papertrail_url
|
37
37
|
|
38
|
-
pass "found drain setup with token #{data['token']}"
|
38
|
+
pass "found drain setup with token #{data['token']} on #{bold app_name}"
|
39
39
|
context.papertrail.system_name![env] = data['token']
|
40
40
|
end
|
41
41
|
|
@@ -26,14 +26,14 @@ module RooOnRails
|
|
26
26
|
requires LogDestinationExists
|
27
27
|
|
28
28
|
def intro
|
29
|
-
|
29
|
+
'Checking that the app is logging to Papertrail...'
|
30
30
|
end
|
31
31
|
|
32
32
|
def call
|
33
33
|
data = context.papertrail.client.list_systems.find { |h|
|
34
34
|
h['hostname'] == system_token
|
35
35
|
}
|
36
|
-
fail! "no system with token '#{system_token}' found" if data.nil?
|
36
|
+
fail! "no system with token '#{system_token}' found on #{bold app_name}" if data.nil?
|
37
37
|
|
38
38
|
if data.syslog.hostname != context.papertrail.dest.host ||
|
39
39
|
data.syslog.port != context.papertrail.dest.port
|
@@ -15,7 +15,7 @@ module RooOnRails
|
|
15
15
|
if File.exist?('config/sidekiq.yml')
|
16
16
|
message = [
|
17
17
|
'Custom Sidekiq settings found.',
|
18
|
-
'
|
18
|
+
'Please see the Roo On Rails readme for more information.'
|
19
19
|
].join("\n")
|
20
20
|
|
21
21
|
fail! message
|
data/lib/roo_on_rails/harness.rb
CHANGED
@@ -2,42 +2,36 @@ require 'thor'
|
|
2
2
|
require 'hashie'
|
3
3
|
require 'roo_on_rails/checks/environment'
|
4
4
|
require 'roo_on_rails/environment'
|
5
|
-
require 'roo_on_rails/checks/
|
6
|
-
require 'roo_on_rails/checks/documentation/playbook'
|
5
|
+
require 'roo_on_rails/checks/environment_independent'
|
7
6
|
|
8
7
|
module RooOnRails
|
9
8
|
class Harness
|
10
9
|
include Thor::Shell
|
11
10
|
|
12
|
-
def initialize(try_fix: false, context: Hashie::Mash.new, dry_run: false)
|
11
|
+
def initialize(try_fix: false, environments: nil, context: Hashie::Mash.new, dry_run: false)
|
13
12
|
@try_fix = try_fix
|
14
13
|
@context = context
|
15
14
|
@dry_run = dry_run
|
15
|
+
@environments = environments
|
16
16
|
end
|
17
17
|
|
18
18
|
def run
|
19
19
|
checks = [
|
20
|
-
Checks::
|
21
|
-
Checks::Documentation::Playbook.new(fix: @try_fix, context: @context, dry_run: @dry_run),
|
20
|
+
Checks::EnvironmentIndependent.new(fix: @try_fix, context: @context, dry_run: @dry_run),
|
22
21
|
]
|
23
22
|
environments.each do |env|
|
24
23
|
checks << Checks::Environment.new(env: env.strip, fix: @try_fix, context: @context, dry_run: @dry_run)
|
25
24
|
end
|
26
25
|
|
27
|
-
checks.
|
28
|
-
|
29
|
-
rescue Shell::CommandFailed
|
30
|
-
say 'A command failed to run, aborting', %i[bold red]
|
31
|
-
exit 2
|
32
|
-
rescue Checks::Failure
|
33
|
-
say 'A check failed, exiting', %i[bold red]
|
34
|
-
exit 1
|
26
|
+
return if checks.map(&:run).all?
|
27
|
+
say 'At least one check failed.', %i[bold red]
|
35
28
|
end
|
36
29
|
|
37
30
|
private
|
38
31
|
|
39
32
|
def environments
|
40
|
-
ENV.fetch('ROO_ON_RAILS_ENVIRONMENTS', 'staging,production')
|
33
|
+
as_string = @environments || ENV.fetch('ROO_ON_RAILS_ENVIRONMENTS', 'staging,production')
|
34
|
+
as_string.split(',')
|
41
35
|
end
|
42
36
|
end
|
43
37
|
end
|
data/lib/roo_on_rails/logfmt.rb
CHANGED
@@ -7,10 +7,6 @@ module RooOnRails
|
|
7
7
|
# @see https://godoc.org/github.com/kr/logfmt The 'reference' parser
|
8
8
|
module Logfmt
|
9
9
|
class << self
|
10
|
-
SPACE = 0x20
|
11
|
-
QUOTE = 0x22
|
12
|
-
EQUALS = 0x3d
|
13
|
-
|
14
10
|
def dump(hash)
|
15
11
|
return nil if hash.nil? || hash.empty?
|
16
12
|
|
@@ -26,18 +22,10 @@ module RooOnRails
|
|
26
22
|
when Array, Hash then JSON.dump(v)
|
27
23
|
else v.respond_to?(:to_json) ? v.to_json : v.inspect
|
28
24
|
end
|
29
|
-
escape(str)
|
30
|
-
end
|
31
|
-
|
32
|
-
def escape(str)
|
33
|
-
return str if ident?(str)
|
34
|
-
|
35
|
-
escaped = str.gsub(/(["\\])/, '\\\\\1')
|
36
|
-
%("#{escaped}")
|
37
|
-
end
|
38
25
|
|
39
|
-
|
40
|
-
str
|
26
|
+
@_escape_re ||= /[[:space:]"']/
|
27
|
+
return str unless @_escape_re =~ str
|
28
|
+
str.inspect
|
41
29
|
end
|
42
30
|
end
|
43
31
|
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'delegate'
|
3
|
+
require 'roo_on_rails/logfmt'
|
4
|
+
|
5
|
+
module RooOnRails
|
6
|
+
# A compatible replacement for the standard Logger to provide context, similar
|
7
|
+
# to `ActiveSupport::TaggedLogging` but with key/value pairs in logfmt format.
|
8
|
+
#
|
9
|
+
# logger = RooOnRails::Logger.new(STDOUT)
|
10
|
+
# logger.with(a: 1, b: 2) { logger.info 'Stuff' }
|
11
|
+
# # Logs "at=INFO msg=Stuff a=1 b=2"
|
12
|
+
#
|
13
|
+
# logger.with(a: 1) { logger.with(b: 2) { logger.info('Stuff') } }
|
14
|
+
# # Logs "at=INFO msg=Stuff a=1 b=2"
|
15
|
+
#
|
16
|
+
# The above methods persist the context in thread local storage so it will be
|
17
|
+
# attached to any logs made within the scope of the block, even in called
|
18
|
+
# methods. However, if your context only applies to the current log then you
|
19
|
+
# can chain off the `with` method.
|
20
|
+
#
|
21
|
+
# logger.with(a: 1, b: 2).info('Stuff')
|
22
|
+
# # Logs "at=INFO msg=Stuff a=1 b=2"
|
23
|
+
#
|
24
|
+
# logger.with(a: 1) { logger.with(b: 2).info('Stuff') }
|
25
|
+
# # Logs "at=INFO msg=Stuff a=1 b=2"
|
26
|
+
#
|
27
|
+
# Hashes, arrays and any complex object that supports `#to_json` will be
|
28
|
+
# output in escaped JSON format so that it can be parsed out of the attribute
|
29
|
+
# values.
|
30
|
+
class Logger < SimpleDelegator
|
31
|
+
def initialize(io = STDOUT)
|
32
|
+
@show_timestamp = io.tty?
|
33
|
+
logger = ::Logger.new(io).tap do |l|
|
34
|
+
l.formatter = method(:_formatter)
|
35
|
+
end
|
36
|
+
super(logger)
|
37
|
+
set_log_level
|
38
|
+
end
|
39
|
+
|
40
|
+
def with(context = {})
|
41
|
+
return Proxy.new(self, context) unless block_given?
|
42
|
+
|
43
|
+
new_context = (_context_stack.last || {}).merge(context)
|
44
|
+
Thread.handle_interrupt(Exception => :never) do
|
45
|
+
begin
|
46
|
+
_context_stack.push(new_context)
|
47
|
+
Thread.handle_interrupt(Exception => :immediate) do
|
48
|
+
yield self
|
49
|
+
end
|
50
|
+
ensure
|
51
|
+
_context_stack.pop
|
52
|
+
end
|
53
|
+
end
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_log_level
|
58
|
+
self.level = ::Logger::Severity.const_get(ENV.fetch('LOG_LEVEL', 'DEBUG'))
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
class Proxy < SimpleDelegator
|
64
|
+
def initialize(logger, context)
|
65
|
+
@context = context
|
66
|
+
super(logger)
|
67
|
+
end
|
68
|
+
|
69
|
+
%w(add debug info warn error fatal unknown).each do |name|
|
70
|
+
define_method name do |*args, &block|
|
71
|
+
__getobj__.with(@context) do
|
72
|
+
__getobj__.public_send(name, *args, &block)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private_constant :Proxy
|
79
|
+
|
80
|
+
TIMESTAMP_FORMAT = '%F %T.%L'.freeze
|
81
|
+
|
82
|
+
def _formatter(severity, datetime, _progname, message)
|
83
|
+
if @show_timestamp
|
84
|
+
"[%s] %7s | %s %s\n" % [
|
85
|
+
datetime.utc.strftime(TIMESTAMP_FORMAT),
|
86
|
+
severity,
|
87
|
+
message,
|
88
|
+
Logfmt.dump(_context_stack.last)
|
89
|
+
]
|
90
|
+
else
|
91
|
+
"%s\n" % Logfmt.dump({
|
92
|
+
at: severity,
|
93
|
+
msg: message
|
94
|
+
}.merge(_context_stack.last))
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def _context_stack
|
99
|
+
# We use our object ID here to avoid conflicting with other instances
|
100
|
+
thread_key = @_context_stack_key ||= "roo_on_rails:logging_context:#{object_id}".freeze
|
101
|
+
Thread.current[thread_key] ||= [{}]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -3,14 +3,16 @@ module RooOnRails
|
|
3
3
|
class Database < Rails::Railtie
|
4
4
|
initializer 'roo_on_rails.database', after: 'active_record.initialize_database' do
|
5
5
|
ActiveSupport.on_load :active_record do
|
6
|
-
|
6
|
+
Rails.logger.with(initializer: 'roo_on_rails.database') do |log|
|
7
|
+
log.debug 'loading'
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
config = ActiveRecord::Base.configurations[Rails.env]
|
10
|
+
config['variables'] ||= {}
|
11
|
+
config['variables']['statement_timeout'] = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
|
12
|
+
config['reaping_frequency'] = ENV['DATABASE_REAPING_FREQUENCY']
|
12
13
|
|
13
|
-
|
14
|
+
ActiveRecord::Base.establish_connection
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module RooOnRails
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
initializer 'roo_on_rails.default_env' do
|
4
|
+
Rails.logger.with initializer: 'roo_on_rails.default_env' do |log|
|
5
|
+
log.debug 'loading'
|
6
|
+
require 'roo_on_rails/environment'
|
7
|
+
RooOnRails::Environment.load
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -4,8 +4,9 @@ module RooOnRails
|
|
4
4
|
module Railties
|
5
5
|
class GoogleOAuth < Rails::Railtie
|
6
6
|
initializer 'roo_on_rails.google_auth.middleware' do |app|
|
7
|
-
|
8
|
-
|
7
|
+
Rails.logger.with initializer: 'roo_on_rails.google_auth' do |log|
|
8
|
+
next unless Config.google_auth_enabled?
|
9
|
+
log.debug 'loading'
|
9
10
|
_add_middleware(app)
|
10
11
|
_add_routes(app)
|
11
12
|
end
|
@@ -13,11 +14,6 @@ module RooOnRails
|
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
|
-
def _if_enabled
|
17
|
-
return unless Config.google_auth_enabled?
|
18
|
-
yield
|
19
|
-
end
|
20
|
-
|
21
17
|
def _add_middleware(app)
|
22
18
|
require 'omniauth'
|
23
19
|
require 'omniauth-google-oauth2'
|
@@ -2,40 +2,44 @@ module RooOnRails
|
|
2
2
|
module Railties
|
3
3
|
class HTTP < Rails::Railtie
|
4
4
|
initializer 'roo_on_rails.http' do |app|
|
5
|
-
|
6
|
-
|
7
|
-
require 'rack/ssl-enforcer'
|
5
|
+
Rails.logger.with initializer: 'roo_on_rails.http' do |log|
|
6
|
+
log.debug 'loading'
|
8
7
|
|
9
|
-
|
8
|
+
require 'rack/timeout/base'
|
9
|
+
require 'rack/ssl-enforcer'
|
10
|
+
require 'roo_on_rails/rack/safe_timeouts'
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
12
|
+
::Rack::Timeout.service_timeout = ENV.fetch('RACK_SERVICE_TIMEOUT', 15).to_i
|
13
|
+
::Rack::Timeout.wait_timeout = ENV.fetch('RACK_WAIT_TIMEOUT', 30).to_i
|
14
|
+
::Rack::Timeout::Logger.level = ::Logger::WARN
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
app.config.middleware.insert_before(
|
17
|
+
::Rack::Runtime,
|
18
|
+
::Rack::Timeout
|
19
|
+
)
|
19
20
|
|
20
|
-
|
21
|
+
middleware_to_insert_before = Rails::VERSION::MAJOR < 4 ? ::ActionDispatch::Cookies : ::Rack::Head
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
# This needs to be inserted low in the stack, before Rails returns the
|
24
|
+
# thread-current connection to the pool.
|
25
|
+
if defined?(ActiveRecord)
|
26
|
+
app.config.middleware.insert_before(
|
27
|
+
middleware_to_insert_before,
|
28
|
+
RooOnRails::Rack::SafeTimeouts
|
29
|
+
)
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
+
if ENV.fetch('ROO_ON_RAILS_RACK_DEFLATE', 'YES').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
|
33
|
+
app.config.middleware.use ::Rack::Deflater
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
# Don't use SslEnforcer in test environment as it breaks Capybara
|
37
|
+
unless Rails.env.test?
|
38
|
+
app.config.middleware.insert_before(
|
39
|
+
middleware_to_insert_before,
|
40
|
+
::Rack::SslEnforcer
|
41
|
+
)
|
42
|
+
end
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module RooOnRails
|
2
|
+
module Railties
|
3
|
+
class Logging < Rails::Railtie
|
4
|
+
initializer 'roo_on_rails.logging.before', before: :initialize_logger do
|
5
|
+
require 'roo_on_rails/logger'
|
6
|
+
Rails.logger = config.logger = RooOnRails::Logger.new
|
7
|
+
Rails.logger.debug 'initializer roo_on_rails.logging.before'
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer 'roo_on_rails.logging.after', after: :initialize_logger do
|
11
|
+
Rails.logger.set_log_level
|
12
|
+
Rails.logger.debug 'initializer roo_on_rails.logging.after'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -2,25 +2,26 @@ module RooOnRails
|
|
2
2
|
module Railties
|
3
3
|
class NewRelic < Rails::Railtie
|
4
4
|
initializer 'roo_on_rails.new_relic' do
|
5
|
-
|
5
|
+
Rails.logger.with initializer: 'roo_on_rails.new_relic' do |log|
|
6
|
+
log.debug 'loading'
|
7
|
+
license_key = ENV['NEW_RELIC_LICENSE_KEY']
|
6
8
|
|
7
|
-
|
9
|
+
if %w(test development).exclude?(Rails.env.to_s) && (license_key == 'override-me')
|
10
|
+
abort 'Aborting: NEW_RELIC_LICENSE_KEY must be set in production environments'
|
11
|
+
end
|
8
12
|
|
9
|
-
|
10
|
-
abort 'Aborting: NEW_RELIC_LICENSE_KEY must be set in production environments'
|
11
|
-
end
|
13
|
+
abort 'Aborting: NEW_RELIC_LICENSE_KEY is required' if license_key.nil?
|
12
14
|
|
13
|
-
|
15
|
+
path = %w(newrelic.yml config/newrelic.yml).map do |p|
|
16
|
+
Pathname.new(p)
|
17
|
+
end.find(&:exist?)
|
18
|
+
if path
|
19
|
+
abort "Aborting: newrelic.yml detected in '#{path.parent.realpath}', should not exist"
|
20
|
+
end
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
end.find(&:exist?)
|
18
|
-
if path
|
19
|
-
abort "Aborting: newrelic.yml detected in '#{path.parent.realpath}', should not exist"
|
22
|
+
require 'newrelic_rpm'
|
23
|
+
::NewRelic::Agent.manual_start unless Rails.env.test?
|
20
24
|
end
|
21
|
-
|
22
|
-
require 'newrelic_rpm'
|
23
|
-
::NewRelic::Agent.manual_start unless Rails.env.test?
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
@@ -4,17 +4,18 @@ module RooOnRails
|
|
4
4
|
module Railties
|
5
5
|
class Routemaster < Rails::Railtie
|
6
6
|
initializer 'roo_on_rails.routemaster' do
|
7
|
-
|
7
|
+
Rails.logger.with initializer: 'roo_on_rails.routemaster' do |log|
|
8
|
+
next unless Config.routemaster_enabled?
|
9
|
+
log.debug 'loading'
|
8
10
|
|
9
|
-
|
11
|
+
abort 'Aborting: ROUTEMASTER_URL and ROUTEMASTER_UUID are required' if bus_details_missing?
|
10
12
|
|
11
|
-
|
13
|
+
require 'routemaster/client'
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
config.uuid = routemaster_uuid
|
15
|
+
::Routemaster::Client.configure do |config|
|
16
|
+
config.url = routemaster_url
|
17
|
+
config.uuid = routemaster_uuid
|
18
|
+
end
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
@@ -8,21 +8,25 @@ module RooOnRails
|
|
8
8
|
module Railties
|
9
9
|
class Sidekiq < Rails::Railtie
|
10
10
|
initializer 'roo_on_rails.sidekiq' do |app|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
Rails.logger.with initializer: 'roo_on_rails.sidekiq' do |log|
|
12
|
+
|
13
|
+
unless RooOnRails::Config.sidekiq_enabled?
|
14
|
+
logger.debug 'skipping'
|
15
|
+
next
|
16
|
+
end
|
17
|
+
|
18
|
+
log.debug 'loading'
|
19
|
+
require 'hirefire-resource'
|
20
|
+
|
15
21
|
config_sidekiq
|
16
22
|
config_sidekiq_metrics
|
17
23
|
config_hirefire(app)
|
18
|
-
else
|
19
|
-
$stderr.puts 'skipping initializer roo_on_rails.sidekiq'
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
23
27
|
def config_hirefire(app)
|
24
28
|
unless ENV['HIREFIRE_TOKEN']
|
25
|
-
warn 'No HIREFIRE_TOKEN token set, auto scaling not enabled'
|
29
|
+
Rails.logger.warn 'No HIREFIRE_TOKEN token set, auto scaling not enabled'
|
26
30
|
return
|
27
31
|
end
|
28
32
|
add_middleware(app)
|
@@ -44,7 +48,7 @@ module RooOnRails
|
|
44
48
|
end
|
45
49
|
end
|
46
50
|
rescue LoadError
|
47
|
-
|
51
|
+
Rails.logger.warn 'Sidekiq metrics unavailable without Sidekiq Pro'
|
48
52
|
end
|
49
53
|
|
50
54
|
def add_middleware(app)
|
@@ -22,7 +22,14 @@ module RooOnRails
|
|
22
22
|
|
23
23
|
def publish!
|
24
24
|
return unless will_publish?
|
25
|
-
@client.send(
|
25
|
+
@client.send(
|
26
|
+
@event,
|
27
|
+
topic,
|
28
|
+
url,
|
29
|
+
async: async?,
|
30
|
+
data: stringify_keys(data),
|
31
|
+
t: timestamp && timestamp.to_i
|
32
|
+
)
|
26
33
|
end
|
27
34
|
|
28
35
|
def topic
|
@@ -41,6 +48,12 @@ module RooOnRails
|
|
41
48
|
nil
|
42
49
|
end
|
43
50
|
|
51
|
+
def timestamp
|
52
|
+
return @model.created_at if created? && @model.respond_to?(:created_at)
|
53
|
+
return @model.updated_at if (updated? || created?) && @model.respond_to?(:updated_at)
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
44
57
|
%i(created updated deleted noop).each do |event_type|
|
45
58
|
define_method :"#{event_type}?" do
|
46
59
|
@event.to_sym == event_type
|
@@ -9,12 +9,12 @@ module RooOnRails
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.register(publisher_class, model_class:)
|
12
|
-
@publishers[model_class] ||= Set.new
|
13
|
-
@publishers[model_class] << publisher_class
|
12
|
+
@publishers[model_class.name] ||= Set.new
|
13
|
+
@publishers[model_class.name] << publisher_class
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.for(model, event)
|
17
|
-
publisher_classes = @publishers[model.class] || @default_publishers
|
17
|
+
publisher_classes = @publishers[model.class.name] || @default_publishers
|
18
18
|
publisher_classes.map { |c| c.new(model, event) }
|
19
19
|
end
|
20
20
|
|
@@ -18,12 +18,13 @@ if defined?(ActiveRecord)
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
%i
|
21
|
+
%i(
|
22
22
|
db:create
|
23
|
+
db:drop
|
23
24
|
db:migrate
|
24
25
|
db:migrate:down
|
25
26
|
db:rollback
|
26
|
-
|
27
|
+
).each do |task|
|
27
28
|
Rake::Task[task].enhance(%i[db:migrate:extend_statement_timeout])
|
28
29
|
end
|
29
30
|
end
|
data/lib/roo_on_rails/version.rb
CHANGED
data/lib/roo_on_rails.rb
CHANGED
@@ -5,7 +5,8 @@ end
|
|
5
5
|
|
6
6
|
if defined?(Rails)
|
7
7
|
require 'dotenv/rails-now'
|
8
|
-
require 'roo_on_rails/
|
8
|
+
require 'roo_on_rails/railties/logging'
|
9
|
+
require 'roo_on_rails/railties/env'
|
9
10
|
require 'roo_on_rails/railties/new_relic'
|
10
11
|
require 'roo_on_rails/railties/database'
|
11
12
|
require 'roo_on_rails/railties/http'
|