No release in over 3 years
Provides interval-based reconnection for ActiveRecord connections. Helps handle RDS failover scenarios by periodically refreshing connections on checkout.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 7.2.0, < 8.2
>= 7.2.0, < 8.2
 Project Readme

ActiveRecord::IntervalReconnect

ActiveRecord extension to reconnect connections at a fixed interval.

Provides interval-based reconnection for ActiveRecord connections. Helps handle RDS failover scenarios by periodically refreshing connections on checkout.

Installation

Install the gem and add to the application's Gemfile by executing:

bundle add activerecord-interval_reconnect

If bundler is not being used to manage dependencies, install the gem by executing:

gem install activerecord-interval_reconnect

Usage

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.

default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
  reconnection_interval: 15

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.

  • Reconnection only occurs on checkout, so it will not interrupt an ongoing transaction.
  • If you have multiple database connections, only those with reconnection_interaval set are affected.

Development

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.

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.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kozy4324/activerecord-interval_reconnect.

License

The gem is available as open source under the terms of the MIT License.