activerecord-interval_reconnect 0.2.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6dd46ef60c92d22f7ecf82aa2d8036a511fb5a9fd90380f212382432b3145ed1
4
+ data.tar.gz: 36a081922758f89f385205355d770083463c36e26006d0d32d9630d690d6f182
5
+ SHA512:
6
+ metadata.gz: 2b8b4ee5a89c9df2fceffdb4f7ea9255253c9d67208287d93be6c66d151fc2969545fb20aca9319294c41b4bfa2405dbddb89621d7e075a115dcf40c866b363f
7
+ data.tar.gz: ac00ffa415dfa5ea97b83f1d310b0dad355f8ec5c63bad26a164e93b67b7ea1177ea9d1a88ae52548d1e37b2d28c5f86e21b1e82c7a2d722a869160442ffd5c9
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Koji NAKAMURA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # ActiveRecord::IntervalReconnect
2
+
3
+ ActiveRecord extension to reconnect connections at a fixed interval.
4
+
5
+ Provides interval-based reconnection for ActiveRecord connections. Helps handle RDS failover scenarios by periodically refreshing connections on checkout.
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```bash
12
+ bundle add activerecord-interval_reconnect
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```bash
18
+ gem install activerecord-interval_reconnect
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Add reconnection_interval to a connection configuration in database.yml. When a connection is checked out from the pool, ActiveRecord will reconnect if the specified number of seconds has passed since the last reconnect.
24
+
25
+ ```
26
+ default: &default
27
+ adapter: sqlite3
28
+ pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
29
+ timeout: 5000
30
+ reconnection_interval: 15
31
+ ```
32
+
33
+ In this example, if more than 15 seconds have elapsed since the last reconnect, the next checkout will trigger `reconnect!`. If `reconnection_interval` is not specified, nothing happens.
34
+
35
+ - Reconnection only occurs on checkout, so it will not interrupt an ongoing transaction.
36
+ - If you have multiple database connections, only those with `reconnection_interaval` set are affected.
37
+
38
+ ## Development
39
+
40
+ 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.
41
+
42
+ 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).
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kozy4324/activerecord-interval_reconnect.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test rubocop]
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module IntervalReconnect
5
+ VERSION = "0.2.0"
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+
5
+ require_relative "interval_reconnect/version"
6
+
7
+ ActiveSupport.on_load(:active_record) do
8
+ ActiveRecord::ConnectionAdapters::AbstractAdapter.set_callback(:checkout, :after) do
9
+ reconnection_interval = @config[:reconnection_interval]
10
+ next unless reconnection_interval
11
+
12
+ @window_start_at ||= Process.clock_gettime(Process::CLOCK_MONOTONIC)
13
+ if (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @window_start_at) > reconnection_interval
14
+ reconnect!
15
+ @window_start_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record/interval_reconnect"
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-interval_reconnect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Koji NAKAMURA
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activerecord
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 7.2.0
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '8.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: 7.2.0
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '8.1'
32
+ - !ruby/object:Gem::Dependency
33
+ name: activesupport
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 7.2.0
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: '8.1'
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 7.2.0
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: '8.1'
52
+ description: Provides interval-based reconnection for ActiveRecord connections. Helps
53
+ handle RDS failover scenarios by periodically refreshing connections on checkout.
54
+ email:
55
+ - kozy4324@gmail.com
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files: []
59
+ files:
60
+ - LICENSE.txt
61
+ - README.md
62
+ - Rakefile
63
+ - lib/active_record/interval_reconnect.rb
64
+ - lib/active_record/interval_reconnect/version.rb
65
+ - lib/activerecord/interval_reconnect.rb
66
+ homepage: https://github.com/kozy4324/activerecord-interval_reconnect
67
+ licenses:
68
+ - MIT
69
+ metadata:
70
+ allowed_push_host: https://rubygems.org
71
+ homepage_uri: https://github.com/kozy4324/activerecord-interval_reconnect
72
+ source_code_uri: https://github.com/kozy4324/activerecord-interval_reconnect
73
+ rubygems_mfa_required: 'true'
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 3.2.0
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubygems_version: 3.7.0
89
+ specification_version: 4
90
+ summary: ActiveRecord extension to reconnect connections at a fixed interval.
91
+ test_files: []