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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 489053db9c987c891db8ef10bc7ce8d513c49193c99b543a5d9610dc80cfe18b
4
- data.tar.gz: a964c8bbf189217897b61237ac6be0fb8c35ba669efae9b65a24f7a5323a7789
3
+ metadata.gz: 0215abbca618956a55b181c88c6d1658ae5e12a0133f9797c0171b8b9f93e56e
4
+ data.tar.gz: 47c9e6c5158adf4ef735de356de2fa613394546a056dde43c1e252873271b790
5
5
  SHA512:
6
- metadata.gz: b09b5eb4644c73a3717d27808b6d9fc7c570b9447a0cfb038952ed862ee240ff880d3650e9688482ea9084c28d429b86663a3e39f55950a179c9b870b33cec00
7
- data.tar.gz: 74bcdd9e164756cfcdf97132a32d3c08d0cc19785261e4ae827a7f73732db504171494eb52bdea994848aaffa6b25675ba7a7395f76297ae9718e06f0b27cb24
6
+ metadata.gz: bd0d01be3aa27dff5752d91317101915db9e58ea1eb89adff6027bf43739328098d4dbd6c849be2f2c095f959fa2ded3c8d8338ee45e31931cc48f0066d641d2
7
+ data.tar.gz: f21e6e927d86119a2d08dab98dce1a9acf2ed528e0773a9241c3dde75f429b2f643612efc6d67494e9c3ceb4c5eaa075d78b83ea98fa5c25a6f396e1b461debb
data/Dockerfile ADDED
@@ -0,0 +1,3 @@
1
+ FROM postgres:15.4
2
+
3
+ RUN sed -i -e"s/^#default_transaction_isolation =.*$/default_transaction_isolation = 'serializable'/" /usr/share/postgresql/postgresql.conf.sample
data/Gemfile CHANGED
@@ -8,5 +8,9 @@ gemspec
8
8
  gem "rake", "~> 13.0"
9
9
 
10
10
  if ENV['AR_VERSION']
11
- gem 'activerecord', ENV['AR_VERSION']
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 `6.0.4.4`, `6.1.4.4` and `7.0.1` versions of ActiveRecord(see [TrxExt::SUPPORTED_AR_VERSIONS](lib/trx_ext/version.rb))
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
- - Setup postgresql server with `serializable` transaction isolation level - you have to set `default_transaction_isolation` config option to `serializable` in your `postgresql.conf` file
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(see [TrxExt::SUPPORTED_AR_VERSIONS](lib/trx_ext/version.rb)) as well.
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
- if Config.db_config
25
- ActiveRecord::Base.establish_connection(Config.db_config)
26
- DummyRecord.setup
27
- end
24
+ DummyRecord.setup
28
25
 
29
26
  IRB.start(__FILE__)
@@ -2,9 +2,7 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
- require_relative '../lib/trx_ext/version'
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))
@@ -0,0 +1,10 @@
1
+ version: "3.5"
2
+
3
+ services:
4
+ postgres:
5
+ image: trx_ext/postgres
6
+ build: .
7
+ ports:
8
+ - 5532:5432
9
+ environment:
10
+ - POSTGRES_PASSWORD=postgres
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
- error_classification = error_classification(error)
31
- if retry_query?(error, retries_count)
32
- if error_classification == :record_not_unique
33
- retries_count += 1
34
- end
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
- def error_classification(error)
46
- case
47
- when error.message.index('deadlock detected')
48
- :deadlock
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
- def retry_query?(error, retryies_count)
57
- classification = error_classification(error)
58
- ActiveRecord::Base.connection.open_transactions == 0 &&
59
- (%i(deadlock serialization_error).include?(classification) ||
60
- classification == :record_not_unique && retryies_count < TrxExt.config.unique_retries)
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
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module TrxExt
4
- VERSION = "1.0.5"
5
- SUPPORTED_AR_VERSIONS = ['~> 6.0', '~> 6.1', '~> 7.0'].freeze
4
+ VERSION = "1.0.6"
6
5
  end
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.5
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-05-11 00:00:00.000000000 Z
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.5
147
- changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.5/CHANGELOG.md
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.10
165
+ rubygems_version: 3.4.15
164
166
  signing_key:
165
167
  specification_version: 4
166
168
  summary: ActiveRecord's transaction extension