mongoid-locking 1.2.0 → 1.3.0
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/Gemfile.lock +1 -1
- data/README.md +3 -1
- data/lib/mongoid/locking/retry.rb +7 -2
- data/lib/mongoid/locking/version.rb +1 -1
- data/lib/mongoid/locking.rb +12 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 896cdc8de472341f894c24adbedf92e07bc88a0d13c602f75233e052391d505b
|
4
|
+
data.tar.gz: 545fb0a99ca2280c696ec2eccab487a1f6b8a5bd898be20707f2cb3406296ff8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51aa29f8661bb0e4c257c22137eff2342b308deb47c8c1c1b68ffeaec32767985e55741011978d427c2333f422abe18e4731a0e91bab186df71180d8e6734e15
|
7
|
+
data.tar.gz: 3b23274fb66538af4dfd938af8f6824dce5d3439f82cbabf6041d15d6f36f1d1fa4e37195d3e5ef3151bae04014d51577bb77ccb5701c44ed7b84b951aeb1ecf
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -81,11 +81,13 @@ def process_with_locking
|
|
81
81
|
end
|
82
82
|
````
|
83
83
|
|
84
|
-
|
85
84
|
The with_locking method at the instance level combines class-level locking with
|
86
85
|
automatic reloading on each retry. This ensures that the instance reflects the
|
87
86
|
latest changes, providing seamless control over optimistic locking.
|
88
87
|
|
88
|
+
NOTE: The `with_locking` method will add a delay between retries to avoid
|
89
|
+
contention. [More info](https://github.com/fullhealthmedical/mongoid-locking/pull/8).
|
90
|
+
|
89
91
|
## Development
|
90
92
|
|
91
93
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -50,12 +50,17 @@ module Mongoid
|
|
50
50
|
begin
|
51
51
|
yield
|
52
52
|
rescue Mongoid::StaleObjectError
|
53
|
-
raise if retries >= max_retries
|
54
|
-
|
55
53
|
retries += 1
|
54
|
+
raise if retries > max_retries
|
55
|
+
|
56
|
+
sleep Mongoid::Locking.backoff_algorithm(retries)
|
56
57
|
retry
|
57
58
|
end
|
58
59
|
end
|
60
|
+
|
61
|
+
def backoff_algorithm(retries)
|
62
|
+
(2 + rand)**retries
|
63
|
+
end
|
59
64
|
end
|
60
65
|
end
|
61
66
|
end
|
data/lib/mongoid/locking.rb
CHANGED
@@ -17,13 +17,19 @@ module Mongoid
|
|
17
17
|
#
|
18
18
|
# @since 0.1.0
|
19
19
|
module Locking
|
20
|
-
|
21
|
-
base
|
22
|
-
|
20
|
+
class << self
|
21
|
+
def included(base)
|
22
|
+
base.field :lock_version, type: Integer
|
23
|
+
base.before_create { self.lock_version = 0 }
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
base.include Mongoid::Locking::Selectable
|
26
|
+
base.include Mongoid::Locking::Reloadable
|
27
|
+
base.include Mongoid::Locking::Retry
|
28
|
+
end
|
29
|
+
|
30
|
+
def backoff_algorithm(retries)
|
31
|
+
(2**retries) + rand
|
32
|
+
end
|
27
33
|
end
|
28
34
|
end
|
29
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-locking
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo RA
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|