mongoid-locker 1.0.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -7
- data/.rspec +1 -2
- data/.rubocop_todo.yml +39 -23
- data/.travis.yml +27 -41
- data/CHANGELOG.md +6 -0
- data/Dangerfile +2 -0
- data/Gemfile +10 -10
- data/Guardfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +88 -36
- data/Rakefile +2 -0
- data/UPGRADING.md +20 -1
- data/lib/config/locales/en.yml +9 -0
- data/lib/mongoid-locker.rb +10 -1
- data/lib/mongoid/locker.rb +243 -142
- data/lib/mongoid/locker/errors.rb +46 -0
- data/lib/mongoid/locker/version.rb +3 -1
- data/lib/mongoid/locker/wrapper.rb +120 -2
- data/mongoid-locker.gemspec +16 -14
- metadata +7 -10
- data/.document +0 -5
- data/lib/mongoid/locker/wrapper4.rb +0 -22
- data/lib/mongoid/locker/wrapper5.rb +0 -27
- data/lib/mongoid/locker/wrapper6.rb +0 -29
- data/lib/mongoid/locker/wrapper7.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83a2fc5d9474fb911afd4cb106587e84aa7209ee8875b578feaabdff226c3be1
|
4
|
+
data.tar.gz: 8bdfc514dd4649646ea3de44ebf0892b6b9b74a83aadffd5d2c5694177842ba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd9b3d0ad671dd6b2bbf862f47cb7b642446d2f8642861de0d755ee7143e61eb60e3a3f6614f235ed79c09085ff408c4f1a4f39707379c358e655748229866c
|
7
|
+
data.tar.gz: 2cb5ec0046da6f2d6f7b58e8bac93ea6297da9ae3279281b68b0528ebe527b0e6b928db29a280e3282e19c34d16b1e289e6947ab45f1bf33c70bf6864ccc4c9d
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
--
|
2
|
-
--format documentation
|
1
|
+
--require spec_helper
|
data/.rubocop_todo.yml
CHANGED
@@ -1,32 +1,37 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2019-10-23 10:17:29 -0400 using RuboCop version 0.75.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 3
|
10
10
|
# Configuration parameters: Include.
|
11
11
|
# Include: **/*.gemfile, **/Gemfile, **/gems.rb
|
12
12
|
Bundler/DuplicatedGem:
|
13
13
|
Exclude:
|
14
14
|
- 'Gemfile'
|
15
15
|
|
16
|
-
# Offense count:
|
16
|
+
# Offense count: 4
|
17
17
|
Metrics/AbcSize:
|
18
|
-
Max:
|
18
|
+
Max: 21
|
19
19
|
|
20
|
-
# Offense count:
|
20
|
+
# Offense count: 10
|
21
21
|
# Configuration parameters: CountComments, ExcludedMethods.
|
22
22
|
# ExcludedMethods: refine
|
23
23
|
Metrics/BlockLength:
|
24
|
-
Max:
|
24
|
+
Max: 292
|
25
25
|
|
26
|
-
# Offense count:
|
26
|
+
# Offense count: 5
|
27
27
|
# Configuration parameters: CountComments, ExcludedMethods.
|
28
28
|
Metrics/MethodLength:
|
29
|
-
Max:
|
29
|
+
Max: 31
|
30
|
+
|
31
|
+
# Offense count: 1
|
32
|
+
# Configuration parameters: CountComments.
|
33
|
+
Metrics/ModuleLength:
|
34
|
+
Max: 104
|
30
35
|
|
31
36
|
# Offense count: 2
|
32
37
|
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
@@ -47,19 +52,20 @@ Naming/PredicateName:
|
|
47
52
|
- 'spec/**/*'
|
48
53
|
- 'lib/mongoid/locker.rb'
|
49
54
|
|
50
|
-
# Offense count:
|
51
|
-
#
|
52
|
-
#
|
53
|
-
|
54
|
-
RSpec/DescribedClass:
|
55
|
+
# Offense count: 12
|
56
|
+
# Configuration parameters: Prefixes.
|
57
|
+
# Prefixes: when, with, without
|
58
|
+
RSpec/ContextWording:
|
55
59
|
Exclude:
|
56
|
-
- 'spec/
|
60
|
+
- 'spec/support/configurations_shared_context.rb'
|
61
|
+
- 'spec/support/populate_database_shared_context.rb'
|
62
|
+
- 'spec/support/reset_shared_context.rb'
|
57
63
|
|
58
|
-
# Offense count:
|
64
|
+
# Offense count: 7
|
59
65
|
# Configuration parameters: Max.
|
60
66
|
RSpec/ExampleLength:
|
61
67
|
Exclude:
|
62
|
-
- 'spec/
|
68
|
+
- 'spec/support/locker_is_included_shared_examples.rb'
|
63
69
|
|
64
70
|
# Offense count: 1
|
65
71
|
# Configuration parameters: CustomTransform, IgnoreMethods.
|
@@ -67,16 +73,21 @@ RSpec/FilePath:
|
|
67
73
|
Exclude:
|
68
74
|
- 'spec/mongoid-locker_spec.rb'
|
69
75
|
|
70
|
-
# Offense count:
|
76
|
+
# Offense count: 5
|
77
|
+
RSpec/LeakyConstantDeclaration:
|
78
|
+
Exclude:
|
79
|
+
- 'spec/support/configurations_shared_context.rb'
|
80
|
+
|
81
|
+
# Offense count: 12
|
71
82
|
# Configuration parameters: .
|
72
83
|
# SupportedStyles: have_received, receive
|
73
84
|
RSpec/MessageSpies:
|
74
85
|
EnforcedStyle: receive
|
75
86
|
|
76
|
-
# Offense count:
|
87
|
+
# Offense count: 11
|
77
88
|
# Configuration parameters: AggregateFailuresByDefault.
|
78
89
|
RSpec/MultipleExpectations:
|
79
|
-
Max:
|
90
|
+
Max: 3
|
80
91
|
|
81
92
|
# Offense count: 2
|
82
93
|
Style/Documentation:
|
@@ -86,12 +97,17 @@ Style/Documentation:
|
|
86
97
|
- 'lib/mongoid/locker.rb'
|
87
98
|
|
88
99
|
# Offense count: 2
|
89
|
-
|
100
|
+
# Cop supports --auto-correct.
|
101
|
+
# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods.
|
102
|
+
# SupportedStyles: predicate, comparison
|
103
|
+
Style/NumericPredicate:
|
90
104
|
Exclude:
|
105
|
+
- 'spec/**/*'
|
91
106
|
- 'lib/mongoid/locker.rb'
|
92
107
|
|
93
|
-
# Offense count:
|
94
|
-
#
|
108
|
+
# Offense count: 33
|
109
|
+
# Cop supports --auto-correct.
|
110
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
95
111
|
# URISchemes: http, https
|
96
112
|
Metrics/LineLength:
|
97
|
-
Max:
|
113
|
+
Max: 250
|
data/.travis.yml
CHANGED
@@ -5,49 +5,37 @@ language: ruby
|
|
5
5
|
|
6
6
|
cache: bundler
|
7
7
|
|
8
|
-
|
9
|
-
-
|
10
|
-
|
8
|
+
script:
|
9
|
+
- bundle exec rspec
|
10
|
+
|
11
|
+
rvm:
|
12
|
+
- 2.3.8
|
13
|
+
- 2.4.5
|
14
|
+
- 2.5.4
|
15
|
+
- 2.6.2
|
16
|
+
- jruby-9.1.17.0
|
17
|
+
- jruby-9.2.6.0
|
18
|
+
|
19
|
+
env:
|
20
|
+
- MONGOID_VERSION=5
|
21
|
+
- MONGOID_VERSION=6
|
22
|
+
- MONGOID_VERSION=7
|
11
23
|
|
12
24
|
matrix:
|
13
25
|
include:
|
14
|
-
- rvm: 2.
|
15
|
-
env:
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
- rvm: 2.4.5
|
23
|
-
env: MONGOID_VERSION=7
|
24
|
-
- rvm: 2.5.3
|
25
|
-
env: MONGOID_VERSION=7
|
26
|
-
before_script: bundle exec danger
|
27
|
-
- rvm: jruby-9.1.17.0
|
28
|
-
env: MONGOID_VERSION=4
|
29
|
-
- rvm: jruby-9.1.17.0
|
30
|
-
env: MONGOID_VERSION=5
|
31
|
-
- rvm: jruby-9.1.17.0
|
32
|
-
env: MONGOID_VERSION=6
|
33
|
-
- rvm: jruby-9.2.4.0
|
34
|
-
env: MONGOID_VERSION=6
|
35
|
-
- rvm: jruby-9.2.4.0
|
36
|
-
env: MONGOID_VERSION=7
|
37
|
-
- name: Code Climate Test Coverage
|
38
|
-
rvm: 2.3.8
|
39
|
-
env: COVERAGE=true
|
40
|
-
script:
|
41
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
42
|
-
- chmod +x ./cc-test-reporter
|
43
|
-
- ./cc-test-reporter before-build
|
44
|
-
- for version in 4 5 6 7; do
|
45
|
-
MONGOID_VERSION=$version bundle update;
|
46
|
-
bundle exec rake;
|
47
|
-
./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.mongoid${version}.json;
|
48
|
-
done
|
26
|
+
- rvm: 2.6.2
|
27
|
+
env:
|
28
|
+
- MONGOID_VERSION=7
|
29
|
+
- COVERAGE=true
|
30
|
+
before_script:
|
31
|
+
- bundle exec rubocop
|
32
|
+
- bundle exec danger
|
33
|
+
after_script:
|
49
34
|
- if [[ "$TRAVIS_TEST_RESULT" == 0 ]]; then
|
50
|
-
|
35
|
+
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter;
|
36
|
+
chmod +x ./cc-test-reporter;
|
37
|
+
./cc-test-reporter before-build;
|
38
|
+
./cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.json coverage/.resultset.json;
|
51
39
|
./cc-test-reporter upload-coverage;
|
52
40
|
fi
|
53
41
|
- rvm: ruby-head
|
@@ -55,8 +43,6 @@ matrix:
|
|
55
43
|
fast_finish: true
|
56
44
|
allow_failures:
|
57
45
|
- rvm: ruby-head
|
58
|
-
- rvm: jruby-9.1.17.0
|
59
|
-
- rvm: jruby-9.2.4.0
|
60
46
|
- rvm: jruby-head
|
61
47
|
|
62
48
|
bundler_args: --without development
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
## Changelog
|
2
2
|
|
3
|
+
### 2.0.0 (2019-10-23)
|
4
|
+
|
5
|
+
* [#79](https://github.com/mongoid/mongoid-locker/pull/79): Update find_and_lock and find_and_unlock methods - [@dks17](https://github.com/dks17).
|
6
|
+
* [#78](https://github.com/mongoid/mongoid-locker/pull/78): Upgrade to v2.0 - [@dks17](https://github.com/dks17).
|
7
|
+
* [#83](https://github.com/mongoid/mongoid-locker/pull/83): Upgraded to RuboCop 0.75.1 - [@dblock](https://github.com/dblock).
|
8
|
+
|
3
9
|
### 1.0.1 (2019-03-23)
|
4
10
|
|
5
11
|
* [#74](https://github.com/mongoid/mongoid-locker/pull/74): Add JRuby tests - [@dks17](https://github.com/dks17).
|
data/Dangerfile
CHANGED
data/Gemfile
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
gemspec
|
2
5
|
|
3
6
|
case ENV['MONGOID_VERSION']
|
4
7
|
when /^7/
|
@@ -7,25 +10,22 @@ when /^6/
|
|
7
10
|
gem 'mongoid', '~> 6.4'
|
8
11
|
when /^5/
|
9
12
|
gem 'mongoid', '~> 5.4'
|
10
|
-
when /^4/
|
11
|
-
gem 'mongoid', '~> 4.0'
|
12
13
|
else
|
13
|
-
gem 'mongoid', '>=
|
14
|
+
gem 'mongoid', '>= 5.0'
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
+
gem 'rake'
|
17
18
|
|
18
19
|
group :development do
|
19
20
|
gem 'guard-rspec'
|
20
|
-
gem 'rb-fsevent', '~> 0.9.1'
|
21
21
|
end
|
22
22
|
|
23
23
|
group :development, :test do
|
24
|
+
gem 'pry-byebug', platforms: :mri
|
25
|
+
|
24
26
|
gem 'mongoid-danger', '~> 0.1.1'
|
25
|
-
gem '
|
26
|
-
gem '
|
27
|
-
gem 'rspec', '~> 3.0'
|
28
|
-
gem 'rubocop'
|
27
|
+
gem 'rspec', '~> 3.8'
|
28
|
+
gem 'rubocop', '0.75.1'
|
29
29
|
gem 'rubocop-rspec'
|
30
30
|
gem 'simplecov', require: false
|
31
31
|
end
|
data/Guardfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,14 +1,20 @@
|
|
1
|
-
#
|
1
|
+
# Mongoid-Locker
|
2
|
+
|
2
3
|
[![Gem Version](https://badge.fury.io/rb/mongoid-locker.svg)](https://badge.fury.io/rb/mongoid-locker)
|
3
4
|
[![Build Status](https://travis-ci.org/mongoid/mongoid-locker.svg?branch=master)](https://travis-ci.org/mongoid/mongoid-locker)
|
4
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/04ee4ee75ff54659300a/maintainability)](https://codeclimate.com/github/mongoid/mongoid-locker/maintainability)
|
5
6
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/04ee4ee75ff54659300a/test_coverage)](https://codeclimate.com/github/mongoid/mongoid-locker/test_coverage)
|
6
7
|
|
7
|
-
Document-level locking for MongoDB via Mongoid. Mongoid-Locker is an easy way to ensure only one process can perform a certain operation on a document at a time.
|
8
|
+
Document-level optimistic locking for MongoDB via Mongoid. Mongoid-Locker is an easy way to ensure only one process can perform a certain operation on a document at a time.
|
9
|
+
|
10
|
+
**NOTE:** Since version `2` Mongoid-Locker relies on MongoDB server time and not current client time, and does not perform any time calculation to get lock or release it. The basis of the current version are unique name of locking and time is set by MongoDB.
|
11
|
+
|
12
|
+
**NOTE:** Please refer to [1-x-stable](https://github.com/mongoid/mongoid-locker/tree/1-x-stable) branch for `1.x.x` documentation. See the [UPGRADING](UPGRADING.md) guide and [CHANGELOG](CHANGELOG.md) for an overview of the changes.
|
8
13
|
|
9
14
|
[Tested](https://travis-ci.org/mongoid/mongoid-locker) against:
|
10
|
-
- MRI: `2.3.8`, `2.4.5`, `2.5.
|
11
|
-
-
|
15
|
+
- MRI: `2.3.8`, `2.4.5`, `2.5.4`, `2.6.2`
|
16
|
+
- JRuby `9.1.17.0`, `9.2.6.0`
|
17
|
+
- Mongoid: `5`, `6`, `7`
|
12
18
|
|
13
19
|
See [.travis.yml](.travis.yml) for the latest test matrix.
|
14
20
|
|
@@ -23,88 +29,134 @@ gem 'mongoid-locker'
|
|
23
29
|
and run `bundle install`. In the model you wish to lock, include `Mongoid::Locker` after `Mongoid::Document`. For example:
|
24
30
|
|
25
31
|
```ruby
|
26
|
-
class
|
32
|
+
class User
|
27
33
|
include Mongoid::Document
|
28
34
|
include Mongoid::Locker
|
29
35
|
|
36
|
+
field :locking_name, type: String
|
30
37
|
field :locked_at, type: Time
|
31
|
-
field :locked_until, type: Time
|
32
38
|
|
33
|
-
field :
|
39
|
+
field :age, type: Integer
|
40
|
+
|
41
|
+
index({ _id: 1, locking_name: 1 }, name: 'mongoid_locker_index', sparse: true, unique: true, expire_after_seconds: lock_timeout)
|
34
42
|
end
|
35
43
|
```
|
36
44
|
|
37
45
|
Then, execute any code you like in a block like so:
|
38
46
|
|
39
47
|
```ruby
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
queue_item.completed_at = Time.now.utc
|
45
|
-
queue_item.save!
|
48
|
+
user.with_lock do
|
49
|
+
user.age = 17
|
50
|
+
user.save!
|
46
51
|
end
|
47
52
|
```
|
48
53
|
|
49
|
-
The `#with_lock` function takes an optional
|
50
|
-
|
51
|
-
The default timeout can also be set on a per-class basis:
|
52
|
-
|
53
|
-
```ruby
|
54
|
-
class QueueItem
|
55
|
-
# ...
|
56
|
-
timeout_lock_after 10
|
57
|
-
end
|
58
|
-
```
|
54
|
+
The `#with_lock` function takes an optional handful of options, so make sure to take a look.
|
59
55
|
|
60
56
|
Note that these locks are only enforced when using `#with_lock`, not at the database level. It's useful for transactional operations, where you can make atomic modification of the document with checks. For example, you could deduct a purchase from a user's balance ... _unless_ they are broke.
|
61
57
|
|
62
|
-
More in-depth method documentation can be found at [
|
58
|
+
More in-depth method documentation can be found at [RubyDoc.info](https://www.rubydoc.info/gems/mongoid-locker).
|
63
59
|
|
64
|
-
### Customizable :
|
65
|
-
By default, Locker uses fields with `:
|
60
|
+
### Customizable :locking_name and :locked_at field names
|
61
|
+
By default, Locker uses fields with `:locking_name` and `:locked_at` names which should be defined in a model.
|
66
62
|
```ruby
|
67
63
|
class User
|
68
64
|
include Mongoid::Document
|
69
65
|
include Mongoid::Locker
|
70
66
|
|
67
|
+
field :locking_name, type: String
|
71
68
|
field :locked_at, type: Time
|
72
|
-
field :locked_until, type: Time
|
73
69
|
end
|
74
70
|
```
|
75
71
|
|
76
|
-
Use `Mongoid::Locker.configure` to setup
|
72
|
+
Use `Mongoid::Locker.configure` to setup parameters which used by Locker for all models where it's included.
|
77
73
|
```ruby
|
78
74
|
Mongoid::Locker.configure do |config|
|
79
|
-
config.
|
80
|
-
config.
|
75
|
+
config.locking_name_field = :global_locking_name
|
76
|
+
config.locked_at_field = :global_locked_at
|
81
77
|
end
|
82
78
|
|
83
79
|
class User
|
84
80
|
include Mongoid::Document
|
85
81
|
include Mongoid::Locker
|
86
82
|
|
83
|
+
field :global_locking_name, type: String
|
87
84
|
field :global_locked_at, type: Time
|
88
|
-
field :global_locked_until, type: Time
|
89
85
|
end
|
90
86
|
```
|
91
87
|
|
92
|
-
The `locker` method in your model accepts
|
88
|
+
The `locker` method in your model accepts options to setup parameters for the model.
|
93
89
|
```ruby
|
94
90
|
class User
|
95
91
|
include Mongoid::Document
|
96
92
|
include Mongoid::Locker
|
97
93
|
|
94
|
+
field :locker_locking_name, type: String
|
98
95
|
field :locker_locked_at, type: Time
|
99
|
-
field :locker_locked_until, type: Time
|
100
96
|
|
101
|
-
locker locked_at_field: :
|
102
|
-
|
97
|
+
locker locked_at_field: :locker_locking_name,
|
98
|
+
locked_at_field: :locker_locked_at
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
102
|
+
### Available parameters for Mongoid::Locker, a class where it's included
|
103
|
+
| parameter | default | options | description |
|
104
|
+
|---|---|---|---|
|
105
|
+
| locking_name_field | `:locking_name` | any field name | field where name of locking is storing, must be of type `String` |
|
106
|
+
| locked_at_field | `:locked_at` | any field name | field where it is storing the time of beginning a lock of a document, must be of type `Time` |
|
107
|
+
| lock_timeout | `5` | | within this time (in seconds) a document is considered as locked |
|
108
|
+
| locker_write_concern | `{ w: 1 }` | see [MongoDB Write Concern](https://docs.mongodb.com/manual/reference/write-concern/#write-concern-specification)| a write concern only used for lock and unlock operations |
|
109
|
+
| maximum_backoff | `60.0` | | the highest timeout (in seconds) between retires to lock a document, reaching that value `#with_lock` method raises `Mongoid::Locker::Errors::DocumentCouldNotGetLock` |
|
110
|
+
| backoff_algorithm | `:exponential_backoff` | `:locked_at_backoff` or [custom algorithm](#custom-backoff_algorithm-and-locking_name_generator) | algorithm used for timeout calculating between retries to lock a document|
|
111
|
+
| locking_name_generator | `:secure_locking_name` | [custom generator](#custom-backoff_algorithm-and-locking_name_generator) | generator used to generate unique name of a lock |
|
112
|
+
|
113
|
+
For instances of a class where `Mongoid::Locker` is included, all parameters of a class are available for reading.
|
114
|
+
```ruby
|
115
|
+
document.lock_timeout
|
116
|
+
#=> 5
|
117
|
+
```
|
118
|
+
|
119
|
+
### Custom :backoff_algorithm and :locking_name_generator
|
120
|
+
A method which is defined in `Mongoid::Locker` are available in a class where it is included.
|
121
|
+
|
122
|
+
Method `#with_lock` passes to the methods a document to which apply `#with_lock` and a hash of options. The hash may look like this:
|
123
|
+
```ruby
|
124
|
+
{ retries: Infinity, reload: true, attempt: 0, locking_name: "71c1ccd4-72d9-4a83-bbed-adf65803bd5d" }
|
125
|
+
```
|
126
|
+
|
127
|
+
A custom backoff algorithmoff **must return** a value more or equal `maximum_backoff` value to force `#with_lock` quit trying to lock a document, otherwise `#with_lock` will be trying to lock a document `INFINITY` times.
|
128
|
+
```ruby
|
129
|
+
Mongoid::Locker.configure do |config|
|
130
|
+
config.backoff_algorithm = :custom_backoff
|
131
|
+
end
|
132
|
+
|
133
|
+
module Mongoid
|
134
|
+
module Locker
|
135
|
+
def self.custom_backoff(doc, _opts)
|
136
|
+
rand > 0.5 ? 5 : doc.maximum_backoff
|
137
|
+
end
|
138
|
+
end
|
103
139
|
end
|
104
140
|
```
|
105
141
|
|
142
|
+
A custom locking name generator **must return** a string to secure uniqueness name of locking.
|
143
|
+
```ruby
|
144
|
+
class User
|
145
|
+
include Mongoid::Document
|
146
|
+
include Mongoid::Locker
|
147
|
+
|
148
|
+
locker locking_name_generator: :custom_locking_name
|
149
|
+
|
150
|
+
field :locker_locking_name, type: String
|
151
|
+
field :locker_locked_at, type: Time
|
152
|
+
|
153
|
+
def self.custom_locking_name(_doc, _opts)
|
154
|
+
SecureRandom.uuid
|
155
|
+
end
|
156
|
+
```
|
157
|
+
|
106
158
|
## Copyright & License
|
107
159
|
|
108
|
-
Copyright (c) 2012-
|
160
|
+
Copyright (c) 2012-2019 Aidan Feldman & Contributors
|
109
161
|
|
110
162
|
MIT License, see [LICENSE](LICENSE.txt) for more information.
|