trx_ext 1.0.4 → 1.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93b7a1f518fdd40ddeeb90c13f994c3cf437fd7f21a4077dafaa432c26085ae1
4
- data.tar.gz: bd95308a108f553e964d14a929516bb43b7736a5248f22694b08e5da19ac881b
3
+ metadata.gz: 0215abbca618956a55b181c88c6d1658ae5e12a0133f9797c0171b8b9f93e56e
4
+ data.tar.gz: 47c9e6c5158adf4ef735de356de2fa613394546a056dde43c1e252873271b790
5
5
  SHA512:
6
- metadata.gz: 036114f10ef556602a66b0b0c407bc0f4acac45e353b650758eb29f23d567addfa53b0db734c3bce53660589e866ca57fc3f70b0fbfc88014669091305548d3c
7
- data.tar.gz: b0abbce63d353477366626597c13cb2de29dfc61376d2dfe8b5dd0787ac248088029348bb207af3d468bb70c7517177ecbf18a9c11ce5e3a95c6f9d2db522ceb
6
+ metadata.gz: bd0d01be3aa27dff5752d91317101915db9e58ea1eb89adff6027bf43739328098d4dbd6c849be2f2c095f959fa2ded3c8d8338ee45e31931cc48f0066d641d2
7
+ data.tar.gz: f21e6e927d86119a2d08dab98dce1a9acf2ed528e0773a9241c3dde75f429b2f643612efc6d67494e9c3ceb4c5eaa075d78b83ea98fa5c25a6f396e1b461debb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.2
1
+ 3.2.2
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Nothing new yet
4
4
 
5
+ ## [1.0.5] - 2022-01-27
6
+
7
+ - Load `Object` extension earlier
8
+
5
9
  ## [1.0.2] - 2022-01-27
6
10
 
7
11
  - Add support of ActiveRecord `7.0.1`
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.4"
5
- SUPPORTED_AR_VERSIONS = %w(6.0.4.7 6.1.5 7.0.2.3).freeze
4
+ VERSION = "1.0.6"
6
5
  end
data/lib/trx_ext.rb CHANGED
@@ -14,12 +14,12 @@ module TrxExt
14
14
 
15
15
  # @return [void]
16
16
  def integrate!
17
+ # Allow to use #wrap_in_trx and #trx methods everywhere
18
+ Object.prepend(TrxExt::ObjectExt)
19
+
17
20
  ActiveSupport.on_load(:active_record) do
18
21
  require 'active_record/connection_adapters/postgresql_adapter'
19
22
 
20
- # Allow to use #wrap_in_trx and #trx methods everywhere
21
- Object.prepend(TrxExt::ObjectExt)
22
-
23
23
  # Patch #transaction
24
24
  ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend(TrxExt::Transaction)
25
25
 
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
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: 2022-04-01 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.4
147
- changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.4/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.2.28
165
+ rubygems_version: 3.4.15
164
166
  signing_key:
165
167
  specification_version: 4
166
168
  summary: ActiveRecord's transaction extension