retry_on_deadlock 0.1.1 → 0.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/README.md +12 -4
- data/lib/retry_on_deadlock/core.rb +5 -3
- data/lib/retry_on_deadlock/version.rb +1 -1
- metadata +6 -7
- data/retry_on_deadlock.gemspec +0 -62
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3fa6f7b40409f47be5931917376c0036a10af233163b7755a6168832eeb8fd7
|
|
4
|
+
data.tar.gz: 95048b05505960f9106fda27d4c68000d901752ff0295819944017eb7549be58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ca0a9c26f0a097105ab04921e8baab8fc527eddd7bce0e249248bde08dd903e9a5ac13759825f79c631334ffc285c8336d7dee1c472e107e398a877047c3270
|
|
7
|
+
data.tar.gz: d298987acdb2b6e1ae084e1d4b933119ab6f5b7a3d24b90cfb51af47961b9b3a1fd4113c9a327cccd740f9ac9941cbe65fb3a5c91bfc4b51f3459dcfe3a428bc
|
data/README.md
CHANGED
|
@@ -35,6 +35,18 @@ Car.transaction(retry_on_deadlock: true) do
|
|
|
35
35
|
end
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
### Per-Transaction Overrides
|
|
39
|
+
|
|
40
|
+
You can override global configuration settings for a specific transaction by passing them as arguments to the `transaction` method. Currently, you can override `max_retries`:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
# Retry this specific transaction up to 5 times (overriding the global setting)
|
|
44
|
+
Car.transaction(retry_on_deadlock: true, max_retries: 5) do
|
|
45
|
+
car = Car.find(1)
|
|
46
|
+
car.update!(name: "Updated Name")
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
|
|
38
50
|
### Configuration
|
|
39
51
|
|
|
40
52
|
You can configure the gem to suit your needs. For example:
|
|
@@ -85,10 +97,6 @@ $ bundle exec rake release
|
|
|
85
97
|
|
|
86
98
|
This will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
87
99
|
|
|
88
|
-
## Contributing
|
|
89
|
-
|
|
90
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/retry_on_deadlock. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/retry_on_deadlock/blob/master/CODE_OF_CONDUCT.md).
|
|
91
|
-
|
|
92
100
|
## License
|
|
93
101
|
|
|
94
102
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -14,7 +14,7 @@ module RetryOnDeadlock
|
|
|
14
14
|
if should_retry?(kwargs)
|
|
15
15
|
transaction_with_lock_handling(*args, **kwargs.merge(retry_count: 0), &block)
|
|
16
16
|
else
|
|
17
|
-
super(*args, **kwargs.except(:retry_on_deadlock), &block)
|
|
17
|
+
super(*args, **kwargs.except(:retry_on_deadlock, :max_retries), &block)
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -26,12 +26,14 @@ module RetryOnDeadlock
|
|
|
26
26
|
# @param [Proc] block The block to execute within the transaction.
|
|
27
27
|
def transaction_with_lock_handling(*args, **kwargs, &block)
|
|
28
28
|
retry_count = kwargs[:retry_count]
|
|
29
|
+
max_retries = kwargs.key?(:max_retries) ? kwargs[:max_retries] : RetryOnDeadlock.configuration.max_retries
|
|
30
|
+
|
|
29
31
|
loop do
|
|
30
32
|
begin
|
|
31
|
-
return transaction(*args, **kwargs.except(:retry_count).merge(retry_on_deadlock: false), &block)
|
|
33
|
+
return transaction(*args, **kwargs.except(:retry_count, :max_retries).merge(retry_on_deadlock: false), &block)
|
|
32
34
|
rescue ActiveRecord::Deadlocked => error
|
|
33
35
|
raise error if inner_transaction?
|
|
34
|
-
raise error if retry_count >=
|
|
36
|
+
raise error if retry_count >= max_retries
|
|
35
37
|
|
|
36
38
|
log_details(error, retry_count) if RetryOnDeadlock.configuration.enable_logging
|
|
37
39
|
retry_count += 1
|
metadata
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: retry_on_deadlock
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aiman Abu Talaah
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-06-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '5.0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
26
|
version: '5.0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: activesupport
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - ">="
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
33
|
version: '5.0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '5.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
@@ -113,7 +113,6 @@ files:
|
|
|
113
113
|
- lib/retry_on_deadlock/configuration.rb
|
|
114
114
|
- lib/retry_on_deadlock/core.rb
|
|
115
115
|
- lib/retry_on_deadlock/version.rb
|
|
116
|
-
- retry_on_deadlock.gemspec
|
|
117
116
|
- sig/retry_on_deadlock.rbs
|
|
118
117
|
homepage: https://github.com/yourusername/deadlock_retry
|
|
119
118
|
licenses:
|
data/retry_on_deadlock.gemspec
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "lib/retry_on_deadlock/version"
|
|
4
|
-
# Gem::Specification.new do |spec|
|
|
5
|
-
# spec.name = "deadlock_retry"
|
|
6
|
-
# spec.version = "0.1.0"
|
|
7
|
-
# spec.authors = ["Your Name"]
|
|
8
|
-
# spec.email = ["your.email@example.com"]
|
|
9
|
-
|
|
10
|
-
# spec.summary = "Automatically retry ActiveRecord transactions on deadlocks."
|
|
11
|
-
# spec.description = "A gem to handle deadlocks in ActiveRecord by retrying transactions and logging details."
|
|
12
|
-
# spec.homepage = "https://github.com/yourusername/deadlock_retry"
|
|
13
|
-
# spec.license = "MIT"
|
|
14
|
-
|
|
15
|
-
# spec.files = Dir["lib/**/*", "README.md", "LICENSE.txt"]
|
|
16
|
-
# spec.require_paths = ["lib"]
|
|
17
|
-
|
|
18
|
-
# spec.add_dependency "activerecord", ">= 5.0"
|
|
19
|
-
# spec.add_dependency "activesupport", ">= 5.0"
|
|
20
|
-
|
|
21
|
-
# spec.add_development_dependency "rspec", "~> 3.0"
|
|
22
|
-
# spec.add_development_dependency "pg", "~> 1.0"
|
|
23
|
-
# spec.add_development_dependency "pry", "~> 0.13"
|
|
24
|
-
# end
|
|
25
|
-
Gem::Specification.new do |spec|
|
|
26
|
-
spec.name = "retry_on_deadlock"
|
|
27
|
-
spec.version = RetryOnDeadlock::VERSION
|
|
28
|
-
spec.authors = ["Aiman Abu Talaah"]
|
|
29
|
-
spec.email = ["aiman.abutalaah@gmail.com"]
|
|
30
|
-
|
|
31
|
-
spec.summary = "Automatically retry ActiveRecord transactions on deadlocks."
|
|
32
|
-
spec.description = "A gem to handle deadlocks in ActiveRecord by retrying transactions and logging details."
|
|
33
|
-
spec.homepage = "https://github.com/yourusername/deadlock_retry"
|
|
34
|
-
spec.license = "MIT"
|
|
35
|
-
spec.required_ruby_version = ">= 3.0.0"
|
|
36
|
-
|
|
37
|
-
# spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
|
|
38
|
-
|
|
39
|
-
spec.metadata["homepage_uri"] = "https://github.com/AimanAbuTalaah/retry_on_deadlock"
|
|
40
|
-
spec.metadata["source_code_uri"] = "https://github.com/AimanAbuTalaah/retry_on_deadlock"
|
|
41
|
-
spec.metadata["changelog_uri"] = "https://github.com/AimanAbuTalaah/retry_on_deadlock"
|
|
42
|
-
|
|
43
|
-
# Specify which files should be added to the gem when it is released.
|
|
44
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
45
|
-
spec.files = Dir.chdir(__dir__) do
|
|
46
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
|
47
|
-
(File.expand_path(f) == __FILE__) ||
|
|
48
|
-
f.start_with?(*%w[bin/ test/ spec/ features/ .git appveyor Gemfile])
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
spec.bindir = "exe"
|
|
52
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
53
|
-
spec.require_paths = ["lib"]
|
|
54
|
-
|
|
55
|
-
spec.add_runtime_dependency "activerecord", "~> 5.0"
|
|
56
|
-
spec.add_runtime_dependency "activesupport", "~> 5.0"
|
|
57
|
-
|
|
58
|
-
spec.add_development_dependency "byebug", "~> 11.0"
|
|
59
|
-
spec.add_development_dependency "rspec", "~> 3.0"
|
|
60
|
-
spec.add_development_dependency "pg", "~> 1.0"
|
|
61
|
-
spec.add_development_dependency "pry", "~> 0.13"
|
|
62
|
-
end
|