trx_ext 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Dockerfile +3 -0
- data/Gemfile +5 -1
- data/README.md +3 -16
- data/bin/console +1 -4
- data/bin/test_all_ar_versions +1 -3
- data/docker-compose.yml +10 -0
- data/lib/trx_ext/retry.rb +17 -25
- data/lib/trx_ext/version.rb +1 -2
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0215abbca618956a55b181c88c6d1658ae5e12a0133f9797c0171b8b9f93e56e
|
4
|
+
data.tar.gz: 47c9e6c5158adf4ef735de356de2fa613394546a056dde43c1e252873271b790
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0d01be3aa27dff5752d91317101915db9e58ea1eb89adff6027bf43739328098d4dbd6c849be2f2c095f959fa2ded3c8d8338ee45e31931cc48f0066d641d2
|
7
|
+
data.tar.gz: f21e6e927d86119a2d08dab98dce1a9acf2ed528e0773a9241c3dde75f429b2f643612efc6d67494e9c3ceb4c5eaa075d78b83ea98fa5c25a6f396e1b461debb
|
data/Dockerfile
ADDED
data/Gemfile
CHANGED
@@ -8,5 +8,9 @@ gemspec
|
|
8
8
|
gem "rake", "~> 13.0"
|
9
9
|
|
10
10
|
if ENV['AR_VERSION']
|
11
|
-
|
11
|
+
# Given ENV['AR_VERSION'] to equal "6.0" will produce
|
12
|
+
# ```ruby
|
13
|
+
# gem 'activerecord', "~> 6.0", "< 6.1"
|
14
|
+
# ```
|
15
|
+
gem 'activerecord', "~> #{ENV['AR_VERSION']}", "< #{ENV['AR_VERSION'].next}"
|
12
16
|
end
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Currently, the implementation only works for ActiveRecord PostgreSQL adapter. Fe
|
|
8
8
|
|
9
9
|
Because the implementation of this gem is a patch for `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter` - carefully test its integration into your project. For example, if your project patches ActiveRecord or if some of your gems patches ActiveRecord - there might be conflicts in the implementation which could potentially lead to the data loss.
|
10
10
|
|
11
|
-
Currently, the implementation is tested for
|
11
|
+
Currently, the implementation is tested for rails v6+.
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
@@ -584,22 +584,13 @@ end
|
|
584
584
|
### Setup
|
585
585
|
|
586
586
|
- After checking out the repo, run `bin/setup` to install dependencies.
|
587
|
-
-
|
588
|
-
- Create pg user and a database. This database will be used to run tests. When running console, this database will be used as a default database to connect to. Example:
|
589
|
-
```shell
|
590
|
-
sudo -u postgres createuser postgres --superuser
|
591
|
-
sudo -u postgres psql --command="CREATE DATABASE trx_ext_db OWNER postgres"
|
592
|
-
```
|
593
|
-
- Setup db connection settings. Copy config sample and edit it to match your created pg user and database:
|
594
|
-
```shell
|
595
|
-
cp spec/support/config/database.yml.sample spec/support/config/database.yml
|
596
|
-
```
|
587
|
+
- run docker-compose using `docker-compose up` command - it starts necessary services
|
597
588
|
|
598
589
|
Now you can run `bin/console` for an interactive prompt that will allow you to experiment.
|
599
590
|
|
600
591
|
### Tests
|
601
592
|
|
602
|
-
You can run tests for currently installed AR using `rspec` command. There is `bin/test_all_ar_versions` executable that allows you to run tests within all supported AR versions
|
593
|
+
You can run tests for currently installed AR using `rspec` command. There is `bin/test_all_ar_versions` executable that allows you to run tests within all supported AR versions.
|
603
594
|
|
604
595
|
### Other
|
605
596
|
|
@@ -616,7 +607,3 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
616
607
|
## Code of Conduct
|
617
608
|
|
618
609
|
Everyone interacting in the TrxExt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/intale/trx_ext/blob/master/CODE_OF_CONDUCT.md).
|
619
|
-
|
620
|
-
## TODO
|
621
|
-
|
622
|
-
- integrate GitHub Actions
|
data/bin/console
CHANGED
@@ -21,9 +21,6 @@ require_relative '../spec/support/dummy_record'
|
|
21
21
|
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
|
22
22
|
TrxExt.logger = ActiveSupport::Logger.new(STDOUT)
|
23
23
|
|
24
|
-
|
25
|
-
ActiveRecord::Base.establish_connection(Config.db_config)
|
26
|
-
DummyRecord.setup
|
27
|
-
end
|
24
|
+
DummyRecord.setup
|
28
25
|
|
29
26
|
IRB.start(__FILE__)
|
data/bin/test_all_ar_versions
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
# frozen_string_literal: true
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
TrxExt::SUPPORTED_AR_VERSIONS.each do |ar_version|
|
5
|
+
%w[6.0 6.1 7.0].each do |ar_version|
|
8
6
|
`rm Gemfile.lock`
|
9
7
|
Process.waitpid(Kernel.spawn({ 'AR_VERSION' => ar_version }, "bundle install --quiet", close_others: true))
|
10
8
|
Process.waitpid(Kernel.spawn({ 'AR_VERSION' => ar_version }, "rspec", close_others: true))
|
data/docker-compose.yml
ADDED
data/lib/trx_ext/retry.rb
CHANGED
@@ -26,38 +26,30 @@ module TrxExt
|
|
26
26
|
retries_count = 0
|
27
27
|
begin
|
28
28
|
yield
|
29
|
-
rescue => error
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
TrxExt.log("Detected transaction rollback condition. Reason - #{error_classification}. Retrying...")
|
36
|
-
retry
|
37
|
-
else
|
38
|
-
raise error
|
39
|
-
end
|
29
|
+
rescue ActiveRecord::SerializationFailure, ActiveRecord::RecordNotUnique, ActiveRecord::Deadlocked => error
|
30
|
+
raise unless retry_query?(error, retries_count)
|
31
|
+
|
32
|
+
retries_count += 1 unless indisputable_retry?(error)
|
33
|
+
TrxExt.log("Detected transaction rollback condition. Reason - #{error.inspect}. Retrying...")
|
34
|
+
retry
|
40
35
|
end
|
41
36
|
end
|
42
37
|
|
43
38
|
private
|
44
39
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
when error.message.index('could not serialize')
|
50
|
-
:serialization_error
|
51
|
-
when error.class == ActiveRecord::RecordNotUnique
|
52
|
-
:record_not_unique
|
53
|
-
end
|
40
|
+
# @param error [ActiveRecord::ActiveRecordError]
|
41
|
+
# @return [Boolean]
|
42
|
+
def indisputable_retry?(error)
|
43
|
+
error.is_a?(ActiveRecord::Deadlocked) || error.is_a?(ActiveRecord::SerializationFailure)
|
54
44
|
end
|
55
45
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
46
|
+
# @param error [ActiveRecord::ActiveRecordError]
|
47
|
+
# @param retries_count [Integer]
|
48
|
+
# @return [Boolean]
|
49
|
+
def retry_query?(error, retries_count)
|
50
|
+
return true if ActiveRecord::Base.connection.open_transactions == 0 && indisputable_retry?(error)
|
51
|
+
|
52
|
+
ActiveRecord::Base.connection.open_transactions == 0 && retries_count < TrxExt.config.unique_retries
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
data/lib/trx_ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trx_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Dzyzenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- ".ruby-version"
|
121
121
|
- CHANGELOG.md
|
122
122
|
- CODE_OF_CONDUCT.md
|
123
|
+
- Dockerfile
|
123
124
|
- Gemfile
|
124
125
|
- LICENSE.txt
|
125
126
|
- README.md
|
@@ -127,6 +128,7 @@ files:
|
|
127
128
|
- bin/console
|
128
129
|
- bin/setup
|
129
130
|
- bin/test_all_ar_versions
|
131
|
+
- docker-compose.yml
|
130
132
|
- lib/trx_ext.rb
|
131
133
|
- lib/trx_ext/callback_pool.rb
|
132
134
|
- lib/trx_ext/config.rb
|
@@ -143,8 +145,8 @@ licenses:
|
|
143
145
|
metadata:
|
144
146
|
allowed_push_host: https://rubygems.org
|
145
147
|
homepage_uri: https://github.com/intale/trx_ext
|
146
|
-
source_code_uri: https://github.com/intale/trx_ext/tree/v1.0.
|
147
|
-
changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.
|
148
|
+
source_code_uri: https://github.com/intale/trx_ext/tree/v1.0.6
|
149
|
+
changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.6/CHANGELOG.md
|
148
150
|
post_install_message:
|
149
151
|
rdoc_options: []
|
150
152
|
require_paths:
|
@@ -160,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
162
|
- !ruby/object:Gem::Version
|
161
163
|
version: '0'
|
162
164
|
requirements: []
|
163
|
-
rubygems_version: 3.4.
|
165
|
+
rubygems_version: 3.4.15
|
164
166
|
signing_key:
|
165
167
|
specification_version: 4
|
166
168
|
summary: ActiveRecord's transaction extension
|