roo_on_rails 2.0.0.pre.pre.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -10,17 +10,34 @@
10
10
  # * GEM_HOME
11
11
  # * BUNDLE_PATH
12
12
  # * BUNDLE_BIN
13
-
13
+ common_ruby_environment: &common_ruby_environment
14
+ environment:
15
+ RAILS_ENV: test
16
+ PGHOST: 127.0.0.1
17
+ PGUSER: postgres
18
+ POSTGRES_HOST_AUTH_METHOD: "trust"
19
+ common_pg_environment_vars: &common_pg_environment_vars
20
+ POSTGRES_USER: postgres
21
+ POSTGRES_DB: ror_testapp_test
22
+ POSTGRES_HOST_AUTH_METHOD: "trust"
14
23
  <%
15
24
  builds = [
16
- ['2.4.6', 'rails_4'],
17
- ['2.4.6', 'rails_5'],
18
- ['2.4.6', 'rails_5_1'],
19
- ['2.4.6', 'rails_5_2'],
20
- ['2.5.5', 'rails_4'],
21
- ['2.5.5', 'rails_5'],
22
- ['2.5.5', 'rails_5_1'],
23
- ['2.5.5', 'rails_5_2']
25
+ ['2.5.9', 'rails_5_2'],
26
+ ['2.5.9', 'rails_6_0'],
27
+ ['2.5.9', 'rails_6_1'],
28
+
29
+ ['2.6.10', 'rails_5_2'],
30
+ ['2.6.10', 'rails_6_0'],
31
+ ['2.6.10', 'rails_6_1'],
32
+
33
+ ['2.7.6', 'rails_6_0'],
34
+ ['2.7.6', 'rails_6_1'],
35
+
36
+ ['3.0.4', 'rails_6_0'],
37
+ ['3.0.4', 'rails_6_1'],
38
+
39
+ ['3.1.2', 'rails_6_1'],
40
+ ['3.1.2', 'rails_7_0']
24
41
  ]
25
42
  %>
26
43
  version: 2
@@ -29,9 +46,11 @@ jobs:
29
46
  build_<%= ruby %>_<%= variant %>:
30
47
  docker:
31
48
  - image: ruby:<%= ruby %>-alpine
49
+ <<: *common_ruby_environment
32
50
  - image: postgres:9.6-alpine
33
51
  environment:
34
52
  PGDATA: /dev/shm/pgdata
53
+ <<: *common_pg_environment_vars
35
54
  - image: redis:4-alpine
36
55
  steps:
37
56
  - checkout
data/.codecov.yml CHANGED
@@ -2,6 +2,9 @@ codecov:
2
2
  notify:
3
3
  require_ci_to_pass: yes
4
4
 
5
+ ignore:
6
+ - "spec/support"
7
+
5
8
  coverage:
6
9
  precision: 2
7
10
  round: down
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.1
1
+ 2.5.9
data/Appraisals CHANGED
@@ -1,29 +1,44 @@
1
- appraise 'rails-4' do
2
- gem 'rails', '~> 4.2'
1
+ appraise 'rails-5-2' do
2
+ gem 'rails', '~> 5.2.0'
3
+ gem 'bootsnap', '>= 1.1.0', require: false
3
4
  gem 'sqlite3', '~> 1.3.6'
4
- gem 'pg', '~> 0.11'
5
- gem 'sprockets', '~>3.0'
5
+ gem 'pg', '~> 0.18'
6
6
  gem 'rake', '13.0.1'
7
+ gem 'dotenv', '~> 2.7.6'
7
8
  end
8
9
 
9
- appraise 'rails-5' do
10
- gem 'rails', '~> 5.0.0'
11
- gem 'sqlite3', '~> 1.3.6'
10
+ appraise 'rails-6-0' do
11
+ gem 'rails', '~> 6.0.3'
12
+ gem 'bootsnap', '>= 1.1.0', require: false
13
+ gem 'sqlite3', '~> 1.4'
12
14
  gem 'pg', '~> 0.18'
13
15
  gem 'rake', '13.0.1'
16
+ gem 'dotenv', '~> 2.7.6'
14
17
  end
15
18
 
16
- appraise 'rails-5-1' do
17
- gem 'rails', '~> 5.1.0'
18
- gem 'sqlite3', '~> 1.3.6'
19
- gem 'pg', '~> 0.18'
20
- gem 'rake', '13.0.1'
19
+ appraise 'rails-6-1' do
20
+ gem 'rails', '~> 6.1.5'
21
+ gem 'bootsnap', require: false
22
+ gem 'sqlite3'
23
+ gem 'pg'
24
+ gem 'rake'
25
+ gem 'net-smtp', require: false
26
+ gem 'net-pop', require: false
27
+ gem 'net-imap', require: false
28
+ gem 'webpacker', '~>3.0'
29
+ gem 'psych', '< 4'
30
+ gem 'dotenv', '~> 2.7.6'
21
31
  end
22
32
 
23
- appraise 'rails-5-2' do
24
- gem 'rails', '~> 5.2.0'
25
- gem 'bootsnap', '>= 1.1.0', require: false
26
- gem 'sqlite3', '~> 1.3.6'
27
- gem 'pg', '~> 0.18'
28
- gem 'rake', '13.0.1'
33
+ appraise 'rails-7-0' do
34
+ gem 'rails', '~> 7.0.3'
35
+ gem 'bootsnap', require: false
36
+ gem 'sqlite3'
37
+ gem 'pg'
38
+ gem 'rake'
39
+ gem 'net-smtp', require: false
40
+ gem 'net-pop', require: false
41
+ gem 'net-imap', require: false
42
+ gem 'webpacker', '~>3.0'
43
+ gem 'psych', '< 4'
29
44
  end
data/CHANGELOG.md CHANGED
@@ -1,3 +1,32 @@
1
+ # v2.2.0
2
+
3
+ Breaking changes:
4
+
5
+ - Drops Rails 4 support
6
+ - Drops Rails 5.0 support
7
+ - Drops Rails 5.1 support
8
+ - Drops Ruby 2.4 support
9
+
10
+ Features:
11
+
12
+ - Adds Rails 6.1 support
13
+ - Adds Rails 7.0 support
14
+ - Adds Ruby 2.7 support
15
+ - Adds Ruby 3.0 support
16
+ - Adds Ruby 3.1 support
17
+
18
+ # v2.1.2
19
+
20
+ Bug fix:
21
+
22
+ - fixes PopulateEnvFromJWT caching issue where a key that couldn't be fetched would be cached
23
+
24
+ # v2.1.0
25
+
26
+ Features:
27
+
28
+ - Rails 6 compatibility
29
+
1
30
  # v2.0.0-pre.2
2
31
 
3
32
  Features:
data/README.md CHANGED
@@ -21,9 +21,6 @@
21
21
  - [Disabling SSL enforcement](#disabling-ssl-enforcement)
22
22
  - [Database configuration](#database-configuration)
23
23
  - [Sidekiq](#sidekiq)
24
- - [HireFire](#hirefire)
25
- - [For Web Dynos](#for-web-dynos)
26
- - [For Sidekiq Workers](#for-sidekiq-workers)
27
24
  - [Logging](#logging)
28
25
  - [Identity](#identity)
29
26
  - [Google OAuth authentication](#google-oauth-authentication)
@@ -137,48 +134,6 @@ NB. If you are migrating to SLA-based queue names, do not set `SIDEKIQ_ENABLED`
137
134
  to `true` before your old queues have finished processing (this will prevent
138
135
  Sidekiq from seeing the old queues at all).
139
136
 
140
- ### HireFire
141
-
142
- #### For Web Dynos
143
-
144
- Web dynos can be autoscaled by HireFire _only_ if it has been configured to use the `Web.Logplex.Load` source and the Heroku runtime metrics lab feature has been enabled:
145
-
146
- ```bash
147
- $ heroku labs:enable log-runtime-metrics -a your-service-name-here
148
- ```
149
-
150
- You will also need a log drain for HireFire, but the RooOnRails helper below should configure this for you. You can check with
151
-
152
- ```bash
153
- $ heroku drains | grep hirefire
154
- https://logdrain.hirefire.io (d.00000000-0000-0000-0000-000000000000)
155
-
156
- # No drain? Add with:
157
- $ heroku drains:add -a your-service-name-here https://logdrain.hirefire.io
158
- ```
159
-
160
- ([HireFire docs for set up](https://help.hirefire.io/guides/logplex/load-logplex))
161
-
162
- #### For Sidekiq Workers
163
-
164
- When `HIREFIRE_TOKEN` is set an endpoint will be mounted at `/hirefire` that
165
- reports the required worker count as a function of queue latency. By default we
166
- add queue names in the style 'within1day', so if we notice an average latency in
167
- that queue of more than an set threshold we'll request one more worker. If we
168
- notice less than a threshold we'll request one less worker. These settings can
169
- be customised via the following ENV variables
170
-
171
- - `WORKER_INCREASE_THRESHOLD` (default 0.5)
172
- - `WORKER_DECREASE_THRESHOLD` (default 0.1)
173
-
174
- When setting the manager up in the HireFire web ui, the following settings must
175
- be used:
176
-
177
- - name: 'worker'
178
- - type: 'Worker.HireFire.JobQueue'
179
- - ratio: 1
180
- - decrementable: 'true'
181
-
182
137
  ### Logging
183
138
 
184
139
  For clearer and machine-parseable log output, the Rails logger is replaced by an
@@ -382,6 +337,11 @@ The command is designed to fix issues in many cases.
382
337
  Pull requests are welcome on GitHub at
383
338
  `https://github.com/deliveroo/roo_on_rails`.
384
339
 
340
+ ## Releasing
341
+
342
+ 1. Bump the version number in `lib/roo_on_rails/version.rb
343
+ 1. Add an entry to the changelog
344
+ 1. After merging to master release e.g. `bundle exec rake release`
385
345
 
386
346
  ## License
387
347
 
data/appraise CHANGED
@@ -4,8 +4,7 @@
4
4
  #
5
5
  require 'yaml'
6
6
 
7
-
8
- RUBIES = ['2.4.5', '2.5.5']
7
+ RUBIES = ['2.5.9', '2.6.10', '2.7.6', '3.0.4', '3.1.2'].freeze
9
8
  APPRAISALS = `appraisal list`.strip.split(/\s+/)
10
9
 
11
10
  # setup
@@ -14,7 +13,7 @@ RUBIES.each do |ruby|
14
13
  system 'rbenv version'
15
14
  system 'rbenv exec ruby -v'
16
15
  system 'rbenv exec bundle check || rbenv exec bundle install'
17
- system "rbenv exec appraisal install"
16
+ system 'rbenv exec appraisal install'
18
17
  end
19
18
 
20
19
  # tests
@@ -7,8 +7,10 @@ gem "guard-rspec"
7
7
  gem "appraisal"
8
8
  gem "webmock"
9
9
  gem "pg", "~> 0.18"
10
- gem "sqlite3"
10
+ gem "sqlite3", "~> 1.3.6"
11
11
  gem "rails", "~> 5.2.0"
12
12
  gem "bootsnap", ">= 1.1.0", require: false
13
+ gem "rake", "13.0.1"
14
+ gem "dotenv", "~> 2.7.6"
13
15
 
14
16
  gemspec path: "../"
@@ -7,7 +7,10 @@ gem "guard-rspec"
7
7
  gem "appraisal"
8
8
  gem "webmock"
9
9
  gem "pg", "~> 0.18"
10
- gem "sqlite3", "~> 1.3.6"
11
- gem "rails", "~> 5.0.0"
10
+ gem "sqlite3", "~> 1.4"
11
+ gem "rails", "~> 6.0.3"
12
+ gem "bootsnap", ">= 1.1.0", require: false
13
+ gem "rake", "13.0.1"
14
+ gem "dotenv", "~> 2.7.6"
12
15
 
13
16
  gemspec path: "../"
@@ -0,0 +1,21 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "guard"
6
+ gem "guard-rspec"
7
+ gem "appraisal"
8
+ gem "webmock"
9
+ gem "pg"
10
+ gem "sqlite3"
11
+ gem "rails", "~> 6.1.5"
12
+ gem "bootsnap", require: false
13
+ gem "rake"
14
+ gem "net-smtp", require: false
15
+ gem "net-pop", require: false
16
+ gem "net-imap", require: false
17
+ gem "webpacker", "~>3.0"
18
+ gem "psych", "< 4"
19
+ gem "dotenv", "~> 2.7.6"
20
+
21
+ gemspec path: "../"
@@ -0,0 +1,20 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "guard"
6
+ gem "guard-rspec"
7
+ gem "appraisal"
8
+ gem "webmock"
9
+ gem "pg"
10
+ gem "sqlite3"
11
+ gem "rails", "~> 6.1.5"
12
+ gem "bootsnap", require: false
13
+ gem "rake"
14
+ gem "net-smtp", require: false
15
+ gem "net-pop", require: false
16
+ gem "net-imap", require: false
17
+ gem "webpacker", "~>3.0"
18
+ gem "psych", "< 4"
19
+
20
+ gemspec path: "../"
@@ -1,12 +1,7 @@
1
1
  require 'delegate'
2
2
  require 'roo_on_rails/logfmt'
3
3
  require 'rails/version'
4
-
5
- if Rails::VERSION::MAJOR < 4
6
- require 'logger'
7
- else
8
- require 'active_support/logger'
9
- end
4
+ require 'active_support/logger'
10
5
 
11
6
  module RooOnRails
12
7
  # A compatible replacement for the standard Logger to provide context, similar
@@ -36,7 +31,7 @@ module RooOnRails
36
31
  class Logger < SimpleDelegator
37
32
  def initialize(io = STDOUT)
38
33
  @show_timestamp = io.tty?
39
- logger = _default_logger_class.new(io).tap do |l|
34
+ logger = ActiveSupport::Logger.new(io).tap do |l|
40
35
  l.formatter = method(:_formatter)
41
36
  end
42
37
  super(logger)
@@ -113,13 +108,5 @@ module RooOnRails
113
108
  thread_key = @_context_stack_key ||= "roo_on_rails:logging_context:#{object_id}".freeze
114
109
  Thread.current[thread_key] ||= [{}]
115
110
  end
116
-
117
- def _default_logger_class
118
- if Rails::VERSION::MAJOR < 4
119
- ::Logger
120
- else
121
- ActiveSupport::Logger
122
- end
123
- end
124
111
  end
125
112
  end
@@ -22,7 +22,8 @@ module RooOnRails
22
22
  @app = app
23
23
  @logger = logger
24
24
  @url_mappings = url_mappings
25
- @keys = @mapped_urls = {}
25
+ @keys = {}
26
+ @mapped_urls = {}
26
27
 
27
28
  if skip_sig_verify && non_prod?
28
29
  @logger.warn "JWTs signature verifification has been switched off in development."
@@ -3,9 +3,34 @@ 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
- Rails.logger.with(initializer: 'roo_on_rails.database') do |log|
7
- log.debug 'loading'
6
+ Rails.logger.debug('[roo_on_rails.database] loading')
8
7
 
8
+ if Gem::Version.new(Rails.version) >= Gem::Version.new('6.1')
9
+ configs = ActiveRecord::Base.configurations.configurations
10
+ old_url_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'primary')
11
+ new_config_hash = old_url_config.configuration_hash.deep_dup
12
+ new_config_hash[:variables] ||= {}
13
+ statement_timeout = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
14
+ # Use -1 to disable setting the statement timeout
15
+ new_config_hash[:variables][:statement_timeout] = statement_timeout unless statement_timeout == '-1'
16
+ new_config_hash[:reaping_frequency] = ENV['DATABASE_REAPING_FREQUENCY'] if ENV.key?('DATABASE_REAPING_FREQUENCY')
17
+ if old_url_config.respond_to?(:url)
18
+ new_url_config = ActiveRecord::DatabaseConfigurations::UrlConfig.new(
19
+ old_url_config.env_name,
20
+ old_url_config.name,
21
+ old_url_config.url,
22
+ new_config_hash
23
+ )
24
+ else
25
+ new_url_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
26
+ old_url_config.env_name,
27
+ old_url_config.name,
28
+ new_config_hash
29
+ )
30
+ end
31
+ configs.delete(old_url_config)
32
+ configs << new_url_config
33
+ else
9
34
  config = ActiveRecord::Base.configurations[Rails.env]
10
35
  config['variables'] ||= {}
11
36
  statement_timeout = ENV.fetch('DATABASE_STATEMENT_TIMEOUT', 200)
@@ -16,8 +41,9 @@ module RooOnRails
16
41
  if ENV.key?('DATABASE_REAPING_FREQUENCY')
17
42
  config['reaping_frequency'] = ENV['DATABASE_REAPING_FREQUENCY']
18
43
  end
19
- ActiveRecord::Base.establish_connection
20
44
  end
45
+
46
+ ActiveRecord::Base.establish_connection
21
47
  end
22
48
  end
23
49
  end
@@ -1,11 +1,9 @@
1
1
  module RooOnRails
2
2
  class Railtie < Rails::Railtie
3
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
4
+ Rails.logger.debug '[roo_on_rails.default_env] loading'
5
+ require 'roo_on_rails/environment'
6
+ RooOnRails::Environment.load
9
7
  end
10
8
  end
11
9
  end
@@ -4,12 +4,10 @@ module RooOnRails
4
4
  module Railties
5
5
  class GoogleOAuth < Rails::Railtie
6
6
  initializer 'roo_on_rails.google_auth.middleware' do |app|
7
- Rails.logger.with initializer: 'roo_on_rails.google_auth' do |log|
8
- next unless Config.google_auth_enabled?
9
- log.debug 'loading'
10
- _add_middleware(app)
11
- _add_routes(app)
12
- end
7
+ next unless Config.google_auth_enabled?
8
+ Rails.logger.debug '[roo_on_rails.google_auth] loading'
9
+ _add_middleware(app)
10
+ _add_routes(app)
13
11
  end
14
12
 
15
13
  private
@@ -2,45 +2,43 @@ module RooOnRails
2
2
  module Railties
3
3
  class HTTP < Rails::Railtie
4
4
  initializer 'roo_on_rails.http' do |app|
5
- Rails.logger.with initializer: 'roo_on_rails.http' do |log|
6
- log.debug 'loading'
5
+ Rails.logger.debug '[roo_on_rails.http] loading'
7
6
 
8
- require 'rack/timeout/base'
9
- require 'rack/ssl-enforcer'
10
- require 'roo_on_rails/rack/safe_timeouts'
7
+ require 'rack/timeout/base'
8
+ require 'rack/ssl-enforcer'
9
+ require 'roo_on_rails/rack/safe_timeouts'
11
10
 
12
- ::Rack::Timeout::Logger.level = ::Logger::WARN
11
+ ::Rack::Timeout::Logger.level = ::Logger::WARN
13
12
 
14
- app.config.middleware.insert_before(
15
- ::Rack::Runtime,
16
- ::Rack::Timeout,
17
- service_timeout: ENV.fetch('RACK_SERVICE_TIMEOUT', 15).to_i,
18
- wait_timeout: ENV.fetch('RACK_WAIT_TIMEOUT', 30).to_i
19
- )
13
+ app.config.middleware.insert_before(
14
+ ::Rack::Runtime,
15
+ ::Rack::Timeout,
16
+ service_timeout: ENV.fetch('RACK_SERVICE_TIMEOUT', 15).to_i,
17
+ wait_timeout: ENV.fetch('RACK_WAIT_TIMEOUT', 30).to_i
18
+ )
20
19
 
21
- middleware_to_insert_before = Rails::VERSION::MAJOR < 4 ? ::ActionDispatch::Cookies : ::Rack::Head
20
+ middleware_to_insert_before = ::Rack::Head
22
21
 
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
22
+ # This needs to be inserted low in the stack, before Rails returns the
23
+ # thread-current connection to the pool.
24
+ if defined?(ActiveRecord)
25
+ app.config.middleware.insert_before(
26
+ middleware_to_insert_before,
27
+ RooOnRails::Rack::SafeTimeouts
28
+ )
29
+ end
31
30
 
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
31
+ if ENV.fetch('ROO_ON_RAILS_RACK_DEFLATE', 'YES').to_s =~ /\A(YES|TRUE|ON|1)\Z/i
32
+ app.config.middleware.use ::Rack::Deflater
33
+ end
35
34
 
36
- # Don't use SslEnforcer in test environment as it breaks Capybara
37
- unless Rails.env.test? ||
38
- ENV.fetch('ROO_ON_RAILS_DISABLE_SSL_ENFORCEMENT', '') =~ /\A(YES|TRUE|ON|1)\Z/i
39
- app.config.middleware.insert_before(
40
- middleware_to_insert_before,
41
- ::Rack::SslEnforcer
42
- )
43
- end
35
+ # Don't use SslEnforcer in test environment as it breaks Capybara
36
+ unless Rails.env.test? ||
37
+ ENV.fetch('ROO_ON_RAILS_DISABLE_SSL_ENFORCEMENT', '') =~ /\A(YES|TRUE|ON|1)\Z/i
38
+ app.config.middleware.insert_before(
39
+ middleware_to_insert_before,
40
+ ::Rack::SslEnforcer
41
+ )
44
42
  end
45
43
  end
46
44
  end
@@ -4,13 +4,14 @@ module RooOnRails
4
4
  module Railties
5
5
  class RooIdentity < Rails::Railtie
6
6
  initializer 'roo_on_rails.roo_identity.middleware' do |app|
7
- Rails.logger.with initializer: 'roo_on_rails.roo_identity' do |log|
8
- if RooOnRails::Rack::PopulateEnvFromJWT.configured?
9
- log.debug 'loading'
10
- _add_middleware(app, log)
11
- else
12
- log.warn 'not configured, roo.identity will be unavailable'
13
- end
7
+ if RooOnRails::Rack::PopulateEnvFromJWT.configured?
8
+ Rails.logger.debug '[roo_on_rails.roo_identity.middleware] loading'
9
+ _add_middleware(app, Rails.logger)
10
+ else
11
+ Rails.logger.warn(
12
+ '[roo_on_rails.roo_identity.middleware] ' \
13
+ ' not configured, roo.identity will be unavailable'
14
+ )
14
15
  end
15
16
  end
16
17
 
@@ -19,7 +20,10 @@ module RooOnRails
19
20
  def _add_middleware(app, log)
20
21
  app.config.middleware.use RooOnRails::Rack::PopulateEnvFromJWT, logger: log
21
22
  rescue LoadError
22
- log.error 'the json-jwt gem is not in the bundle so Roo Identity will not be available'
23
+ log.error(
24
+ '[roo_on_rails.roo_identity.middleware] ' \
25
+ 'the json-jwt gem is not in the bundle so Roo Identity will not be available'
26
+ )
23
27
  end
24
28
  end
25
29
  end
@@ -8,27 +8,15 @@ module RooOnRails
8
8
  module Railties
9
9
  class SidekiqIntegration < Rails::Railtie
10
10
  initializer 'roo_on_rails.sidekiq' do |app|
11
- Rails.logger.with initializer: 'roo_on_rails.sidekiq' do |log|
12
- unless RooOnRails::Config.sidekiq_enabled?
13
- log.debug 'skipping'
14
- next
15
- end
16
-
17
- log.debug 'loading'
18
- require 'hirefire-resource'
19
-
20
- config_sidekiq
21
- config_sidekiq_metrics
22
- config_hirefire(app)
11
+ unless RooOnRails::Config.sidekiq_enabled?
12
+ Rails.logger.debug '[roo_on_rails.sidekiq] skipping'
13
+ next
23
14
  end
24
- end
25
15
 
26
- def config_hirefire(app)
27
- unless ENV['HIREFIRE_TOKEN']
28
- Rails.logger.warn 'No HIREFIRE_TOKEN token set, auto scaling not enabled'
29
- return
30
- end
31
- add_middleware(app)
16
+ Rails.logger.debug '[roo_on_rails.sidekiq] loading'
17
+
18
+ config_sidekiq
19
+ config_sidekiq_metrics
32
20
  end
33
21
 
34
22
  def config_sidekiq
@@ -8,12 +8,37 @@ if defined?(ActiveRecord)
8
8
 
9
9
  namespace :migrate do
10
10
  task extend_statement_timeout: :environment do
11
- if ActiveRecord::VERSION::MAJOR >= 4
11
+ rails_version = Gem::Version.new(Rails.version)
12
+
13
+ if rails_version < Gem::Version.new('6.1')
12
14
  config = ActiveRecord::Base.configurations[Rails.env]
13
15
  config['variables'] ||= {}
14
16
  config['variables']['statement_timeout'] = ENV.fetch('MIGRATION_STATEMENT_TIMEOUT', 10_000)
15
- ActiveRecord::Base.establish_connection
17
+ else
18
+ configs = ActiveRecord::Base.configurations.configurations
19
+ old_url_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'primary')
20
+ new_config_hash = old_url_config.configuration_hash.deep_dup
21
+ new_config_hash[:variables] ||= {}
22
+ new_config_hash[:variables][:statement_timeout] = ENV.fetch('MIGRATION_STATEMENT_TIMEOUT', 10_000)
23
+ if old_url_config.respond_to?(:url)
24
+ new_url_config = ActiveRecord::DatabaseConfigurations::UrlConfig.new(
25
+ old_url_config.env_name,
26
+ old_url_config.name,
27
+ old_url_config.url,
28
+ new_config_hash
29
+ )
30
+ else
31
+ new_url_config = ActiveRecord::DatabaseConfigurations::HashConfig.new(
32
+ old_url_config.env_name,
33
+ old_url_config.name,
34
+ new_config_hash
35
+ )
36
+ end
37
+ configs.delete(old_url_config)
38
+ configs << new_url_config
16
39
  end
40
+
41
+ ActiveRecord::Base.establish_connection
17
42
  end
18
43
  end
19
44
  end
@@ -1,3 +1,3 @@
1
1
  module RooOnRails
2
- VERSION = '2.0.0-pre.2'.freeze
2
+ VERSION = '2.2.0'.freeze
3
3
  end
data/lib/roo_on_rails.rb CHANGED
@@ -5,7 +5,6 @@ end
5
5
 
6
6
  if defined?(Rails)
7
7
  require 'dotenv/rails-now'
8
- require 'roo_on_rails/railties/logging'
9
8
  require 'roo_on_rails/railties/env'
10
9
  require 'roo_on_rails/railties/database'
11
10
  require 'roo_on_rails/railties/http'