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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59b03918904c46ce2770150d4b8d20d2b25ab735e6409982e804a9dbab8c4231
4
- data.tar.gz: 316a1a9851bccd6580aedd95a9e5089a7b5a2ce4f9f2bc2b07a1af4f9ff4a263
3
+ metadata.gz: 896cdc8de472341f894c24adbedf92e07bc88a0d13c602f75233e052391d505b
4
+ data.tar.gz: 545fb0a99ca2280c696ec2eccab487a1f6b8a5bd898be20707f2cb3406296ff8
5
5
  SHA512:
6
- metadata.gz: dc860e6b8d43e812c6b7df124f72e1319041e795006f9dfd2c845cf0ee53d474c20d3d2c50b7d12e10e9b0b4f2eeb4180be38e6baa304b4bef132c14fcd89c9a
7
- data.tar.gz: d545996296a982692f906ed2aa9ccd490855c153c6b949186552814250454168c0c8d8147efc8d5f094fb2f617a0ebc8c30ff02d8f93600143f227972a9fc83b
6
+ metadata.gz: 51aa29f8661bb0e4c257c22137eff2342b308deb47c8c1c1b68ffeaec32767985e55741011978d427c2333f422abe18e4731a0e91bab186df71180d8e6734e15
7
+ data.tar.gz: 3b23274fb66538af4dfd938af8f6824dce5d3439f82cbabf6041d15d6f36f1d1fa4e37195d3e5ef3151bae04014d51577bb77ccb5701c44ed7b84b951aeb1ecf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [1.3.0]
2
+
3
+ - Add: delay between retries for `with_locking` method [#8](https://github.com/fullhealthmedical/mongoid-locking/pull/8)
4
+
1
5
  ## [1.2.0]
2
6
 
3
7
  - Add: with_locking method [#6](https://github.com/fullhealthmedical/mongoid-locking/pull/6)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongoid-locking (1.2.0)
4
+ mongoid-locking (1.3.0)
5
5
  mongoid (~> 7.2)
6
6
 
7
7
  GEM
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mongoid
4
4
  module Locking
5
- VERSION = "1.2.0"
5
+ VERSION = "1.3.0"
6
6
  end
7
7
  end
@@ -17,13 +17,19 @@ module Mongoid
17
17
  #
18
18
  # @since 0.1.0
19
19
  module Locking
20
- def self.included(base)
21
- base.field :lock_version, type: Integer
22
- base.before_create { self.lock_version = 0 }
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
- base.include Mongoid::Locking::Selectable
25
- base.include Mongoid::Locking::Reloadable
26
- base.include Mongoid::Locking::Retry
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.2.0
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: 2023-12-11 00:00:00.000000000 Z
11
+ date: 2024-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid