trx_ext 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/trx_ext/object_ext.rb +14 -11
- data/lib/trx_ext/retry.rb +3 -3
- data/lib/trx_ext/version.rb +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93b7a1f518fdd40ddeeb90c13f994c3cf437fd7f21a4077dafaa432c26085ae1
|
4
|
+
data.tar.gz: bd95308a108f553e964d14a929516bb43b7736a5248f22694b08e5da19ac881b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 036114f10ef556602a66b0b0c407bc0f4acac45e353b650758eb29f23d567addfa53b0db734c3bce53660589e866ca57fc3f70b0fbfc88014669091305548d3c
|
7
|
+
data.tar.gz: b0abbce63d353477366626597c13cb2de29dfc61376d2dfe8b5dd0787ac248088029348bb207af3d468bb70c7517177ecbf18a9c11ce5e3a95c6f9d2db522ceb
|
data/CHANGELOG.md
CHANGED
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
|
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))
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
data/lib/trx_ext/object_ext.rb
CHANGED
@@ -5,29 +5,32 @@ module TrxExt
|
|
5
5
|
# Wraps specified method in an +ActiveRecord+ transaction.
|
6
6
|
#
|
7
7
|
# @example
|
8
|
-
# class
|
9
|
-
#
|
10
|
-
#
|
8
|
+
# class User < ActiveRecord::Base
|
9
|
+
# class << self
|
10
|
+
# wrap_in_trx def find_or_create(name)
|
11
|
+
# user = find_by(name: name)
|
12
|
+
# user ||= create(name: name, title: 'Default')
|
13
|
+
# user
|
14
|
+
# end
|
11
15
|
# end
|
12
16
|
# end
|
13
17
|
#
|
14
|
-
#
|
15
|
-
# order.gnosis(93)
|
18
|
+
# User.find_or_create('some name')
|
16
19
|
# # (0.6ms) BEGIN
|
17
|
-
# #
|
20
|
+
# # User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."name" = $1 LIMIT 1 [["name", 'some name']]
|
21
|
+
# # User Create (1.8 ms) INSERT INTO "users" ("name", "title") VALUES ($1, $2) RETURNING "id" [["name", "some name"], ["title", "Default"]]
|
18
22
|
# # (0.2ms) COMMIT
|
19
|
-
# # => 418
|
20
23
|
#
|
21
24
|
# @param method [Symbol] a name of the method
|
22
25
|
# @return [Symbol]
|
23
26
|
def wrap_in_trx(method)
|
24
27
|
module_to_prepend = Module.new do
|
25
28
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def #{method}(...)
|
30
|
+
trx do
|
31
|
+
super
|
32
|
+
end
|
29
33
|
end
|
30
|
-
end
|
31
34
|
RUBY
|
32
35
|
end
|
33
36
|
prepend module_to_prepend
|
data/lib/trx_ext/retry.rb
CHANGED
@@ -28,10 +28,10 @@ module TrxExt
|
|
28
28
|
yield
|
29
29
|
rescue => error
|
30
30
|
error_classification = error_classification(error)
|
31
|
-
if error_classification == :record_not_unique
|
32
|
-
retries_count += 1
|
33
|
-
end
|
34
31
|
if retry_query?(error, retries_count)
|
32
|
+
if error_classification == :record_not_unique
|
33
|
+
retries_count += 1
|
34
|
+
end
|
35
35
|
TrxExt.log("Detected transaction rollback condition. Reason - #{error_classification}. Retrying...")
|
36
36
|
retry
|
37
37
|
else
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Dzyzenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -143,8 +143,8 @@ licenses:
|
|
143
143
|
metadata:
|
144
144
|
allowed_push_host: https://rubygems.org
|
145
145
|
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.
|
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
148
|
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|