isolator 1.1.1 → 1.2.0
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +6 -3
- data/lib/isolator/adapters/background_jobs/active_job.rb +1 -1
- data/lib/isolator/database_cleaner_support.rb +17 -2
- data/lib/isolator/orm_adapters/active_record.rb +2 -1
- data/lib/isolator/plugins/database_subtransactions.rb +20 -0
- data/lib/isolator/version.rb +1 -1
- data/lib/isolator.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c367300194152c4e2d8adb2c9ff4ab37cc66f9e1eab3e5a1d1576b98fb4970b
|
|
4
|
+
data.tar.gz: c132274cc0936d897f2ecfda8d4c1523db73d5a803f5516ed8eb655fda9f9586
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8eb94aeb576bb42fe9b267403cde9d6418964db34c111ca23e5a8f415fc85aa936eab2da5647eec2878526e0d5998a6b40e09c68fd55afa5ef5648bb8f66ba12
|
|
7
|
+
data.tar.gz: 6285571a44a18c0d21816d48c7580f1a9a0167fedae5db5d5ff757f1485561bef15798f6781e7b7347fe0d87105931a0fd42560abb6b52f1e3fdb223d58785be
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
## master
|
|
4
4
|
|
|
5
|
+
## 1.2.0 (2025-11-07)
|
|
6
|
+
|
|
7
|
+
- Use `ActiveRecord::Base.lease_connection` instead of `ActiveRecord::Base.connection`, if available. ([@viralpraxis][])
|
|
8
|
+
|
|
9
|
+
- Add ability to limit subtransaction amount. ([@dnamsons][])
|
|
10
|
+
|
|
11
|
+
This feature is disabled by default, opt-in via: `Isolator.config.max_subtransactions_depth = :desired_depth`.
|
|
12
|
+
|
|
13
|
+
## 1.1.2 (2025-10-16)
|
|
14
|
+
|
|
15
|
+
- Fix `database_cleaner` support: require `base.rb` explicitly. ([@viralpraxis][])
|
|
16
|
+
|
|
17
|
+
- Fix checking for Rails versions between 8.0 and 8.1. ([@sunny][])
|
|
18
|
+
|
|
5
19
|
## 1.1.1 (2025-03-12)
|
|
6
20
|
|
|
7
21
|
- Fix handling Rails 8 `enqueue_after_transaction_commit` logic. ([@palkan][])
|
|
@@ -155,3 +169,4 @@ This, for example, makes Isolator compatible with Rails multi-database apps.
|
|
|
155
169
|
[@tagirahmad]: https://github.com/tagirahmad
|
|
156
170
|
[@arthurWD]: https://github.com/arthurWD
|
|
157
171
|
[@joshuay03]: https://github.com/joshuay03
|
|
172
|
+
[@viralpraxis]: https://github.com/viralpraxis
|
data/README.md
CHANGED
|
@@ -108,7 +108,10 @@ Isolator.configure do |config|
|
|
|
108
108
|
config.ignorer = Isolator::Ignorer
|
|
109
109
|
|
|
110
110
|
# Turn on/off raising exceptions for simultaneous transactions to different databases
|
|
111
|
-
config.
|
|
111
|
+
config.disallow_per_thread_concurrent_transactions = false
|
|
112
|
+
|
|
113
|
+
# Limit the amount of allowed nested transactions
|
|
114
|
+
config.max_subtransactions_depth = 5
|
|
112
115
|
end
|
|
113
116
|
```
|
|
114
117
|
|
|
@@ -132,13 +135,13 @@ Isolator.after_isolate do
|
|
|
132
135
|
end
|
|
133
136
|
|
|
134
137
|
# This callback is called every time a new transaction is open (root or nested)
|
|
135
|
-
Isolator.
|
|
138
|
+
Isolator.on_transaction_begin do |event|
|
|
136
139
|
puts "New transaction from #{event[:connection_id]}. " \
|
|
137
140
|
"Current depth: #{event[:depth]}"
|
|
138
141
|
end
|
|
139
142
|
|
|
140
143
|
# This callback is called every time a transaction is completed
|
|
141
|
-
Isolator.
|
|
144
|
+
Isolator.on_transaction_end do |event|
|
|
142
145
|
puts "Transaction completed from #{event[:connection_id]}. " \
|
|
143
146
|
"Current depth: #{event[:depth]}"
|
|
144
147
|
end
|
|
@@ -6,7 +6,7 @@ Isolator.isolate :active_job,
|
|
|
6
6
|
exception_class: Isolator::BackgroundJobError,
|
|
7
7
|
details_message: ->(obj) {
|
|
8
8
|
"#{obj.class.name}" \
|
|
9
|
-
"#{
|
|
9
|
+
"#{" (#{obj.arguments.join(", ")})" if obj.arguments.any?}"
|
|
10
10
|
},
|
|
11
11
|
ignore_on: ->(job) {
|
|
12
12
|
config = job.class.try(:enqueue_after_transaction_commit)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "database_cleaner/active_record/base"
|
|
3
4
|
require "database_cleaner/active_record/transaction"
|
|
4
5
|
::DatabaseCleaner::ActiveRecord::Transaction.prepend(
|
|
5
6
|
Module.new do
|
|
6
7
|
def start
|
|
7
8
|
super
|
|
8
|
-
|
|
9
|
+
|
|
10
|
+
connection_id = connection.object_id
|
|
11
|
+
|
|
9
12
|
Isolator.set_connection_threshold(
|
|
10
13
|
Isolator.transactions_threshold(connection_id) + 1,
|
|
11
14
|
connection_id
|
|
@@ -13,12 +16,24 @@ require "database_cleaner/active_record/transaction"
|
|
|
13
16
|
end
|
|
14
17
|
|
|
15
18
|
def clean
|
|
16
|
-
connection_id =
|
|
19
|
+
connection_id = connection.object_id
|
|
20
|
+
|
|
17
21
|
Isolator.set_connection_threshold(
|
|
18
22
|
Isolator.transactions_threshold(connection_id) - 1,
|
|
19
23
|
connection_id
|
|
20
24
|
)
|
|
25
|
+
|
|
21
26
|
super
|
|
22
27
|
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def connection
|
|
32
|
+
if Gem::Version.new("7.2") <= Gem::Version.new(Rails::VERSION::STRING)
|
|
33
|
+
connection_class.lease_connection
|
|
34
|
+
else
|
|
35
|
+
connection_class.connection
|
|
36
|
+
end
|
|
37
|
+
end
|
|
23
38
|
end
|
|
24
39
|
)
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
require_relative "active_support_subscriber"
|
|
4
4
|
|
|
5
5
|
# We rely on this feature introduced in 7.1.0.beta1: https://github.com/rails/rails/pull/49192
|
|
6
|
-
if ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1
|
|
6
|
+
if (ActiveRecord::VERSION::MAJOR >= 7 && ActiveRecord::VERSION::MINOR >= 1) ||
|
|
7
|
+
ActiveRecord.version >= Gem::Version.new("7.1")
|
|
7
8
|
require_relative "active_support_transaction_subscriber"
|
|
8
9
|
Isolator::ActiveSupportTransactionSubscriber.subscribe!
|
|
9
10
|
else
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Isolator
|
|
4
|
+
class Configuration
|
|
5
|
+
attr_accessor :max_subtransactions_depth
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class MaxSubtransactionsExceededError < UnsafeOperationError
|
|
9
|
+
MESSAGE = "Allowed subtransaction amount exceeded"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
Isolator.on_transaction_begin do |event|
|
|
13
|
+
next if Isolator.config.max_subtransactions_depth.nil?
|
|
14
|
+
|
|
15
|
+
depth = event[:depth]
|
|
16
|
+
next unless (depth - 1) > Isolator.config.max_subtransactions_depth
|
|
17
|
+
|
|
18
|
+
Isolator.notify(exception: MaxSubtransactionsExceededError.new, backtrace: caller)
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/isolator/version.rb
CHANGED
data/lib/isolator.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: isolator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vladimir Dementyev
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sniffer
|
|
@@ -318,6 +318,7 @@ files:
|
|
|
318
318
|
- lib/isolator/orm_adapters/active_support_transaction_subscriber.rb
|
|
319
319
|
- lib/isolator/orm_adapters/rom_active_support.rb
|
|
320
320
|
- lib/isolator/plugins/concurrent_database_transactions.rb
|
|
321
|
+
- lib/isolator/plugins/database_subtransactions.rb
|
|
321
322
|
- lib/isolator/railtie.rb
|
|
322
323
|
- lib/isolator/simple_hashie.rb
|
|
323
324
|
- lib/isolator/version.rb
|