Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
🔀 #1 init env etc
Browse files Browse the repository at this point in the history
close #1
  • Loading branch information
simon-dunamu committed Jan 16, 2022
2 parents 884d50e + fdc1c38 commit b09bb0e
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 158 deletions.
5 changes: 5 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[ -x "$(command -v toilet)" ] && toilet -f term -F border --gay " activerecord-mysql-reconnect "

export STARSHIP_CONFIG=$(PWD)/.starship.toml

source_env_if_exists .envrc.local
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ tmp
test.rb
*.bak
*.swp
/gemfiles/*.lock
gemfiles
.envrc.local
.issue_title
.idea
.starship.toml
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.1
45 changes: 0 additions & 45 deletions .travis.yml

This file was deleted.

28 changes: 8 additions & 20 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
appraise "activerecord-4.2" do
gem "activerecord", "~> 4.2.0"
gem "mysql2", "< 0.5"
end

appraise "activerecord-5.0" do
gem "activerecord", "~> 5.0.0"
end

appraise "activerecord-5.1" do
gem "activerecord", "~> 5.1.0"
appraise "activerecord-6.1" do
gem "activerecord", "~> 6.1.0"
end

appraise "activerecord-5.2" do
gem "activerecord", "~> 5.2.0"
end
# appraise "activerecord-7.0" do
# gem "activerecord", "~> 7.0.0"
# end

appraise "activerecord-6.0" do
gem "activerecord", "~> 6.0.2"
end

appraise "activerecord-master" do
gem "activerecord", git: "https://github.com/rails/rails.git"
end
# appraise "activerecord-master" do
# gem "activerecord", git: "https://github.com/rails/rails.git"
# end
44 changes: 39 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
# 이 Fork 에 대한 설명

* ⚠️ [winebarrel/activerecord-mysql-reconnect](https://github.com/winebarrel/activerecord-mysql-reconnect) 이 Archive 상태라서, 지원 타겟 범위를 줄여서 포크합니다.
* 지원타겟 : mysql8 , ActiveRecord ~> 6.1

## 빌드와 배포

### 인증

* GH_TOKEN 은 https://github.com/settings/tokens 에서 획득한다.

```shell
# bundle config https://rubygems.pkg.github.com/ffdd USERNAME:TOKEN
# VERSION 은 lib/activerecord/mysql/reconnect/version.rb 를 따른다.

echo ":github: Bearer ${GH_TOKEN}" >> ~/.gem/credentials
chmod 600 ~/.gem/credentials
```

### 실행

```shell
rake build
gem push --key github --host https://rubygems.pkg.github.com/ffdd pkg/activerecord-mysql-reconnect-${VERSION}.gem
```

## Usage

```ruby
gem "activerecord-mysql-reconnect", source: "https://rubygems.pkg.github.com/ffdd"
```



# activerecord-mysql-reconnect
## Introduction

It is the library to reconnect automatically when ActiveRecord is disconnected from MySQL.

[![Gem Version](https://badge.fury.io/rb/activerecord-mysql-reconnect.svg)](http://badge.fury.io/rb/activerecord-mysql-reconnect)
[![Build Status](https://travis-ci.org/winebarrel/activerecord-mysql-reconnect.svg?branch=master)](https://travis-ci.org/winebarrel/activerecord-mysql-reconnect)
[//]: # ([![Gem Version]&#40;https://badge.fury.io/rb/activerecord-mysql-reconnect.svg&#41;]&#40;http://badge.fury.io/rb/activerecord-mysql-reconnect&#41;)

## Installation

Expand Down Expand Up @@ -118,7 +152,7 @@ It requires the following:

```sh
bundle install
bundle exec appraisal install
bundle exec appraisal activerecord-4.2 rake
bundle exec appraisal activerecord-5.0 rake

bundle exec appraisal activerecord-6.1 rake
bundle exec appraisal activerecord-7.0 rake
```
3 changes: 3 additions & 0 deletions activerecord-mysql-reconnect.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ Gem::Specification.new do |spec|
# '~> 4.2.6'
spec.add_dependency 'activerecord'
spec.add_dependency 'mysql2'
spec.add_dependency 'retriable', '~> 3.1'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '>= 3.0.0'
spec.add_development_dependency "appraisal"
spec.add_development_dependency 'pry'
spec.add_development_dependency 'amazing_print'
end
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mysql_for_ar_mysql_reconn:
image: "mysql:5.6"
image: "mysql:8"
ports:
- "14407:3306"
environment:
Expand Down
8 changes: 0 additions & 8 deletions gemfiles/activerecord_4.2.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord_5.0.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord_5.1.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord_5.2.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord_6.0.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/activerecord_master.gemfile

This file was deleted.

3 changes: 2 additions & 1 deletion lib/activerecord-mysql-reconnect.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'active_support'
require 'retriable'

ActiveSupport.on_load :active_record do
require_relative 'activerecord/mysql/reconnect'
end
end
14 changes: 11 additions & 3 deletions lib/activerecord/mysql/reconnect/abstract_mysql_adapter_ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'retriable'

module Activerecord::Mysql::Reconnect::ExecuteWithReconnect
def execute(sql, name = nil)
retryable(sql, name) do |sql_names|
Expand All @@ -15,6 +17,8 @@ def execute(sql, name = nil)
class ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter
prepend Activerecord::Mysql::Reconnect::ExecuteWithReconnect

FAILOVER_RETRY_INTERVALS = [0.2, 0.5, 1.0, 2.0, 3.0, 3.0, 3.0].freeze

private

def retryable(sql, name, &block)
Expand All @@ -23,7 +27,9 @@ def retryable(sql, name, &block)
transaction = current_transaction

if sql =~ /\ABEGIN\z/i and transaction.is_a?(ActiveRecord::ConnectionAdapters::NullTransaction)
def transaction.state; nil; end
def transaction.state
nil;
end
end

Activerecord::Mysql::Reconnect.retryable(
Expand All @@ -33,8 +39,10 @@ def transaction.state; nil; end
:on_error => proc {
unless block_with_reconnect
block_with_reconnect = proc do |i|
reconnect_without_retry!
block.call(i)
::Retriable.retriable(intervals: FAILOVER_RETRY_INTERVALS) do
reconnect_without_retry!
block.call(i)
end
end
end
},
Expand Down
Loading

0 comments on commit b09bb0e

Please sign in to comment.