activerecord_connection_reaper 0.4.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cde5ce57597f3080ebda91544487f81477143a38d99355e4eb8ee4e70d0b75e3
4
- data.tar.gz: 23d8417049ec5aa708458063d2227ef7825a62f8e54b44c64f9b083ab5f1280e
3
+ metadata.gz: d968492d405f6e4366e20abc75c85936fe8b942fa1cc15201bae93a4fdba0330
4
+ data.tar.gz: 18b015b09be74f7da8055fe4a0d980a4b9b3ad9d6da14a1a7af11eaa69495fdf
5
5
  SHA512:
6
- metadata.gz: ebaff298730cb4acbeaff6adf2e92fb6ed31471ba178e5b50ffeff410a6cb92bcec683d1bed824ec143dd550897825eecea8f280b2f34565cf00e4d989ff1409
7
- data.tar.gz: f30372920b56840936cb5cb4bdfc29360fde15421480605ec6cbec4c2cfb5eaa74e495dad983d1bfa37cbf72b3b2e522a663ae6b8e7b48a6c43e63341713a740
6
+ metadata.gz: f361ef7835d55a6da71626c383ef4e7eaaf1ae0543b1899714faff75974a5e8c3cca27afa2257ca2d2c093733bffebc202d309853abcc2d54c787a78a76b7ac1
7
+ data.tar.gz: 78158526f2fbf1cc30bd14fc79a20640e4647782da2c735dd5730b39d309fd956764018ecd775a2c4a113f97cdacb2fb811262a09dd3e0bfde8f772112f663d3
data/README.md CHANGED
@@ -1,39 +1,38 @@
1
- # ActiverecordConnectionReaper
1
+ # Retire old database connections just like Rails v8.1
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ Rails v8.1 introduced [some new options][1] for managing database connections,
4
+ particularly a few that are useful when running against a pooler, e.g.
5
+ PgBouncer, namely:
4
6
 
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/activerecord_connection_reaper`. To experiment with that code, run `bin/console` for an interactive prompt.
7
+ - **max_age**: number of seconds the pool will allow the connection to exist
8
+ before retiring it at next checkin. (default Float::INFINITY).
9
+ - **pool_jitter**: maximum reduction factor to apply to max_age interval
10
+ (default 0.2; range 0.0-1.0).
6
11
 
7
- ## Installation
8
-
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
12
+ An existing (but not well-documented) parameter that is also useful in this
13
+ scenario is **reaping_frequency**, which determines how often the reaper
14
+ thread checks for connections to retire (it defaults to 60 seconds).
10
15
 
11
- Install the gem and add to the application's Gemfile by executing:
16
+ However, there's a problem here: **this is only supported as of Rails v8.1**.
17
+ Maybe your site isn't running the latest and greatest yet. Maybe... *gasp*
18
+ maybe you're still on Ruby v2.5! What is a poor developer to do? Stop whining
19
+ and update, obviously. While you're working on that, you can use this gem.
12
20
 
13
- ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
- ```
21
+ ## Installation
16
22
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
23
+ Add this line to your application's Gemfile:
18
24
 
19
- ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
25
+ ```ruby
26
+ gem 'activerecord_connection_reaper'
21
27
  ```
22
28
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
29
+ Then install it:
34
30
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activerecord_connection_reaper.
31
+ $ bundle install
36
32
 
37
- ## License
33
+ Once you do that, you can use the `max_age`, `pool_jitter`, and `reaping_frequency`
34
+ options in your database configuration almost as if you were actually on Rails v8.1.
35
+ Note that this gem is purposefully not compatible with Rails v8.1, to make sure you
36
+ remember to remove it when you ARE finally able to update.
38
37
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
38
+ [1]: https://api.rubyonrails.org/v8.1.3/classes/ActiveRecord/ConnectionAdapters/ConnectionPool.html#class-ActiveRecord::ConnectionAdapters::ConnectionPool-label-Options
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordConnectionReaper
4
- VERSION = '0.4.0'
4
+ VERSION = '0.6.0'
5
5
  end
@@ -1,8 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'activerecord_connection_reaper/version'
4
- require_relative 'activerecord_connection_reaper/railtie'
5
- require 'active_record'
4
+ require 'active_support'
6
5
 
7
- module ActiveRecordConnectionReaper
6
+ ActiveSupport.on_load(:active_record) do
7
+ require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/abstract_adapter_track_connected_since' # rubocop:disable Layout/LineLength
8
+ require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/reaper_check_max_age'
9
+ require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/pool_max_age'
10
+
11
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::AbstractAdapterTrackConnectedSince) # rubocop:disable Layout/LineLength
12
+ ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::ReaperCheckMaxAge) # rubocop:disable Layout/LineLength
13
+ ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::PoolMaxAge) # rubocop:disable Layout/LineLength
8
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_connection_reaper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miriam Technologies
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-05-21 00:00:00.000000000 Z
11
+ date: 2026-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -31,7 +31,7 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '8.1'
33
33
  - !ruby/object:Gem::Dependency
34
- name: railties
34
+ name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
@@ -64,7 +64,6 @@ files:
64
64
  - lib/activerecord_connection_reaper/extensions/active_record/connection_adapters/abstract_adapter_track_connected_since.rb
65
65
  - lib/activerecord_connection_reaper/extensions/active_record/connection_adapters/pool_max_age.rb
66
66
  - lib/activerecord_connection_reaper/extensions/active_record/connection_adapters/reaper_check_max_age.rb
67
- - lib/activerecord_connection_reaper/railtie.rb
68
67
  - lib/activerecord_connection_reaper/version.rb
69
68
  homepage: https://github.com/miriamtech/activerecord_connection_reaper
70
69
  licenses:
@@ -1,17 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'rails'
4
-
5
- module ActiveRecordConnectionReaper
6
- class Railtie < Rails::Railtie
7
- initializer 'activerecord_connection_reaper.apply_patches' do
8
- require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/abstract_adapter_track_connected_since' # rubocop:disable Layout/LineLength
9
- require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/reaper_check_max_age'
10
- require 'activerecord_connection_reaper/extensions/active_record/connection_adapters/pool_max_age'
11
-
12
- ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::AbstractAdapterTrackConnectedSince) # rubocop:disable Layout/LineLength
13
- ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::ReaperCheckMaxAge) # rubocop:disable Layout/LineLength
14
- ActiveRecord::ConnectionAdapters::ConnectionPool.prepend(ActiveRecordConnectionReaper::Extensions::ActiveRecord::ConnectionAdapters::PoolMaxAge) # rubocop:disable Layout/LineLength
15
- end
16
- end
17
- end