mongoid-locker 2.2.0 → 2.3.1
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/.github/workflows/danger-comment.yml +19 -0
- data/.github/workflows/danger.yml +17 -14
- data/.github/workflows/lint.yml +29 -0
- data/.github/workflows/release.yml +30 -0
- data/.github/workflows/test.yml +78 -51
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/.rubocop.yml +137 -2
- data/.rubocop_todo.yml +106 -54
- data/.spellcheck.txt +78 -0
- data/CHANGELOG.md +18 -0
- data/Dangerfile +3 -1
- data/Gemfile +27 -7
- data/README.md +73 -23
- data/RELEASING.md +19 -51
- data/Rakefile +22 -3
- data/UPGRADING.md +4 -6
- data/lib/mongoid/locker/version.rb +1 -1
- data/lib/mongoid/locker.rb +12 -4
- data/mongoid-locker.gemspec +2 -3
- data/script/release.rb +17 -0
- metadata +13 -5
- data/.github/workflows/rubocop.yml +0 -13
data/.spellcheck.txt
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
activesupport
|
|
2
|
+
afeld
|
|
3
|
+
Aidan
|
|
4
|
+
amanfrinati
|
|
5
|
+
api
|
|
6
|
+
backoff
|
|
7
|
+
bbed
|
|
8
|
+
BSON
|
|
9
|
+
Bundler
|
|
10
|
+
cesarizu
|
|
11
|
+
chainable
|
|
12
|
+
CHANGELOG
|
|
13
|
+
Changelog
|
|
14
|
+
changelog
|
|
15
|
+
ClassMethods
|
|
16
|
+
commit's
|
|
17
|
+
config
|
|
18
|
+
Customizable
|
|
19
|
+
dblock
|
|
20
|
+
DocumentCouldNotGetLock
|
|
21
|
+
EmbeddedLockChild
|
|
22
|
+
EmbeddedLockParent
|
|
23
|
+
english
|
|
24
|
+
env
|
|
25
|
+
expr
|
|
26
|
+
Feldman
|
|
27
|
+
Fixnum
|
|
28
|
+
forwardable
|
|
29
|
+
Gemfile
|
|
30
|
+
gemspec
|
|
31
|
+
github
|
|
32
|
+
InvalidParameter
|
|
33
|
+
isdbgrid
|
|
34
|
+
JRuby
|
|
35
|
+
klass
|
|
36
|
+
linter
|
|
37
|
+
localTime
|
|
38
|
+
LockError
|
|
39
|
+
md
|
|
40
|
+
Mongoid
|
|
41
|
+
mongoid
|
|
42
|
+
MongoidHistory
|
|
43
|
+
MongoidLockerRelease
|
|
44
|
+
mongos
|
|
45
|
+
mooremo
|
|
46
|
+
msg
|
|
47
|
+
nchainani
|
|
48
|
+
ObjectId
|
|
49
|
+
param
|
|
50
|
+
pschrammel
|
|
51
|
+
Rakefile
|
|
52
|
+
randikabanura
|
|
53
|
+
rb
|
|
54
|
+
README
|
|
55
|
+
rsosag
|
|
56
|
+
RSpec
|
|
57
|
+
rspec
|
|
58
|
+
Rubinius
|
|
59
|
+
RuboCop
|
|
60
|
+
RubyDoc
|
|
61
|
+
RubyGems
|
|
62
|
+
saisrinivasan
|
|
63
|
+
scpike
|
|
64
|
+
SecureRandom
|
|
65
|
+
Sharded
|
|
66
|
+
sharded
|
|
67
|
+
ShardedLockDocument
|
|
68
|
+
sharding
|
|
69
|
+
SimpleCov
|
|
70
|
+
sivagollapalli
|
|
71
|
+
subclasses
|
|
72
|
+
tolsen
|
|
73
|
+
TTL
|
|
74
|
+
txt
|
|
75
|
+
utc
|
|
76
|
+
wuhuizuo
|
|
77
|
+
YAML
|
|
78
|
+
yml
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
## Changelog
|
|
2
2
|
|
|
3
|
+
### 2.3.1 (2026-11-24)
|
|
4
|
+
|
|
5
|
+
* [#115](https://github.com/mongoid/mongoid-locker/pull/115): Lint Markdown, YAML, and spelling with rubocop-md, rubocop-prose, rubocop-spellcheck, and rubocop-yaml in a separate Lint workflow, and clean up documentation - [@dblock](https://github.com/dblock).
|
|
6
|
+
* [#116](https://github.com/mongoid/mongoid-locker/pull/116): Run CI pushes only on the default branch, cancel superseded pull request runs, skip duplicate lint in the test matrix, and bound job times - [@dblock](https://github.com/dblock).
|
|
7
|
+
* [#117](https://github.com/mongoid/mongoid-locker/pull/117): Release with ruby-gem-release from a manually dispatched GitHub Actions workflow using RubyGems Trusted Publishing, with dry runs - [@dblock](https://github.com/dblock).
|
|
8
|
+
* [#119](https://github.com/mongoid/mongoid-locker/pull/119): Upgrade danger-pr-comment to 0.3.0 from the `danger` organization and skip empty Danger report comments - [@dblock](https://github.com/dblock).
|
|
9
|
+
* [#120](https://github.com/mongoid/mongoid-locker/pull/120): Date release headings as `YYYY-MM-DD`, matching earlier releases, instead of ruby-gem-release's default `YYYY/MM/DD` - [@dblock](https://github.com/dblock).
|
|
10
|
+
|
|
11
|
+
### 2.3.0 (2026-10-15)
|
|
12
|
+
|
|
13
|
+
* [#19](https://github.com/mongoid/mongoid-locker/issues/19): Add real sharded-cluster integration coverage for locking collections sharded by ranged and hashed `_id` - [@dblock](https://github.com/dblock).
|
|
14
|
+
* [#81](https://github.com/mongoid/mongoid-locker/issues/81): Document and test updating embedded documents under a parent lock, including stale references after the default reload - [@dblock](https://github.com/dblock).
|
|
15
|
+
* [#111](https://github.com/mongoid/mongoid-locker/pull/111): Replace the retired coverage integration with SimpleCov reporting to Coveralls and update CI and coverage badges - [@dblock](https://github.com/dblock).
|
|
16
|
+
* [#110](https://github.com/mongoid/mongoid-locker/pull/110): Modernize CI through Ruby 4.0, Mongoid 9 and MongoDB 8 while preserving legacy combinations and declaring missing test dependencies - [@dblock](https://github.com/dblock).
|
|
17
|
+
* [#109](https://github.com/mongoid/mongoid-locker/pull/109): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock).
|
|
18
|
+
* [#109](https://github.com/mongoid/mongoid-locker/pull/109): Remove support for Ruby 2.x - [@dblock](https://github.com/dblock).
|
|
19
|
+
* [#109](https://github.com/mongoid/mongoid-locker/pull/109): Add support for Ruby 4.0 - [@dblock](https://github.com/dblock).
|
|
20
|
+
|
|
3
21
|
### 2.2.0 (2025-06-22)
|
|
4
22
|
|
|
5
23
|
* [#107](https://github.com/mongoid/mongoid-locker/pull/107): Revert introduction of `forwardable` to ensure compatibility with mongoid-history - [@scpike](https://github.com/scpike).
|
data/Dangerfile
CHANGED
data/Gemfile
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
source 'https://rubygems.org'
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
-
case ENV
|
|
7
|
-
when /^9/
|
|
8
|
-
gem 'mongoid', '~> 9.0'
|
|
6
|
+
case ENV.fetch('MONGOID_VERSION', nil)
|
|
9
7
|
when /^8/
|
|
10
8
|
gem 'mongoid', '~> 8.0'
|
|
11
9
|
when /^7/
|
|
@@ -15,9 +13,13 @@ when /^6/
|
|
|
15
13
|
when /^5/
|
|
16
14
|
gem 'mongoid', '~> 5.4'
|
|
17
15
|
else
|
|
18
|
-
gem 'mongoid', '
|
|
16
|
+
gem 'mongoid', '~> 9.0'
|
|
19
17
|
end
|
|
20
18
|
|
|
19
|
+
gem 'base64'
|
|
20
|
+
gem 'benchmark'
|
|
21
|
+
gem 'mutex_m'
|
|
22
|
+
gem 'ostruct'
|
|
21
23
|
gem 'rake'
|
|
22
24
|
|
|
23
25
|
group :development do
|
|
@@ -25,13 +27,31 @@ group :development do
|
|
|
25
27
|
end
|
|
26
28
|
|
|
27
29
|
group :development, :test do
|
|
30
|
+
if ENV.fetch('MONGOID_VERSION', '').start_with?('5') && RUBY_ENGINE == 'ruby'
|
|
31
|
+
gem 'bigdecimal', '~> 1.3.5'
|
|
32
|
+
else
|
|
33
|
+
gem 'bigdecimal'
|
|
34
|
+
end
|
|
28
35
|
gem 'pry-byebug', platforms: :mri
|
|
29
36
|
|
|
37
|
+
if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.7')
|
|
38
|
+
gem 'danger', require: false
|
|
39
|
+
gem 'danger-changelog', require: false
|
|
40
|
+
gem 'danger-pr-comment', require: false
|
|
41
|
+
end
|
|
30
42
|
gem 'mongoid-compatibility'
|
|
31
|
-
gem 'mongoid-danger', '~> 0.2.0'
|
|
32
43
|
gem 'mongoid-history'
|
|
33
44
|
gem 'rspec', '~> 3.9'
|
|
34
|
-
gem 'rubocop', '0.81.0'
|
|
35
|
-
gem 'rubocop-rspec', '1.38.1'
|
|
36
45
|
gem 'simplecov', require: false
|
|
46
|
+
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3')
|
|
47
|
+
gem 'commonmarker', '~> 2.10', require: false
|
|
48
|
+
gem 'rubocop', '~> 1.92'
|
|
49
|
+
gem 'rubocop-md', '~> 3.0', require: false
|
|
50
|
+
gem 'rubocop-prose', '~> 0.2', require: false
|
|
51
|
+
gem 'rubocop-rake', '~> 0.7', require: false
|
|
52
|
+
gem 'rubocop-rspec', '~> 3.10', require: false
|
|
53
|
+
gem 'rubocop-spellcheck', '~> 0.2', require: false
|
|
54
|
+
gem 'rubocop-yaml', '~> 0.1.0', require: false
|
|
55
|
+
gem 'ruby-gem-release', '0.9.0', require: false
|
|
56
|
+
end
|
|
37
57
|
end
|
data/README.md
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
# Mongoid-Locker
|
|
2
2
|
|
|
3
|
-
[](https://badge.fury.io/rb/mongoid-locker)
|
|
4
|
-
[](https://github.com/mongoid/mongoid-locker/actions/workflows/test.yml)
|
|
5
|
-
[](https://codeclimate.com/github/mongoid/mongoid-locker/maintainability)
|
|
6
|
-
[](https://codeclimate.com/github/mongoid/mongoid-locker/test_coverage)
|
|
3
|
+
[](https://badge.fury.io/rb/mongoid-locker) [](https://github.com/mongoid/mongoid-locker/actions/workflows/test.yml?query=branch%3Amaster) [](https://coveralls.io/github/mongoid/mongoid-locker?branch=master)
|
|
7
4
|
|
|
8
5
|
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
6
|
|
|
@@ -12,7 +9,8 @@ Document-level optimistic locking for MongoDB via Mongoid. Mongoid-Locker is an
|
|
|
12
9
|
**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.
|
|
13
10
|
|
|
14
11
|
[Tested](https://github.com/mongoid/mongoid-locker/actions) against:
|
|
15
|
-
|
|
12
|
+
|
|
13
|
+
- MRI: `3.x`, `4.x`
|
|
16
14
|
- JRuby `9.1.17.0`, `9.2.11.1`
|
|
17
15
|
- Mongoid: `5`, `6`, `7`, `8`, `9`
|
|
18
16
|
|
|
@@ -55,8 +53,27 @@ Note that these locks are only enforced when using `#with_lock`, not at the data
|
|
|
55
53
|
|
|
56
54
|
More in-depth method documentation can be found at [RubyDoc.info](https://www.rubydoc.info/gems/mongoid-locker).
|
|
57
55
|
|
|
58
|
-
###
|
|
56
|
+
### Updating Embedded Documents
|
|
57
|
+
|
|
58
|
+
Lock the root document and retrieve embedded documents **inside** the `with_lock` block. By default, acquiring a lock reloads the root document before yielding, replacing its cached embedded documents. An embedded document reference obtained before locking is therefore stale: changing it and saving the reloaded parent does not persist that child's changes. Unsaved changes made before acquiring the lock can also be discarded by the reload.
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
parent.with_lock do
|
|
62
|
+
child = parent.children.first
|
|
63
|
+
child.status = 2
|
|
64
|
+
parent.option = 4
|
|
65
|
+
parent.save!
|
|
66
|
+
end
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
If you select a particular child before locking, keep its ID and retrieve it again inside the block with `parent.children.find(child_id)`. This preserves the default reload, so the update works with the current persisted state.
|
|
70
|
+
|
|
71
|
+
Alternatively, `parent.with_lock(reload: false)` preserves existing in-memory embedded references, but does not refresh the parent or its children after acquiring the lock. Use it only when you deliberately want to work with the state already loaded; acquiring the lock does not make that state current.
|
|
72
|
+
|
|
73
|
+
### Customizable `locking_name` and `locked_at` Field Names
|
|
74
|
+
|
|
59
75
|
By default, Locker uses fields with `:locking_name` and `:locked_at` names which should be defined in a model.
|
|
76
|
+
|
|
60
77
|
```ruby
|
|
61
78
|
class User
|
|
62
79
|
include Mongoid::Document
|
|
@@ -68,6 +85,7 @@ end
|
|
|
68
85
|
```
|
|
69
86
|
|
|
70
87
|
Use `Mongoid::Locker.configure` to setup parameters which used by Locker for all models where it's included.
|
|
88
|
+
|
|
71
89
|
```ruby
|
|
72
90
|
Mongoid::Locker.configure do |config|
|
|
73
91
|
config.locking_name_field = :global_locking_name
|
|
@@ -84,6 +102,7 @@ end
|
|
|
84
102
|
```
|
|
85
103
|
|
|
86
104
|
The `locker` method in your model accepts options to setup parameters for the model.
|
|
105
|
+
|
|
87
106
|
```ruby
|
|
88
107
|
class User
|
|
89
108
|
include Mongoid::Document
|
|
@@ -92,37 +111,42 @@ class User
|
|
|
92
111
|
field :locker_locking_name, type: String
|
|
93
112
|
field :locker_locked_at, type: Time
|
|
94
113
|
|
|
95
|
-
locker
|
|
114
|
+
locker locking_name_field: :locker_locking_name,
|
|
96
115
|
locked_at_field: :locker_locked_at
|
|
97
116
|
end
|
|
98
117
|
```
|
|
99
118
|
|
|
100
|
-
### Available
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
|
104
|
-
|
|
|
105
|
-
|
|
|
106
|
-
|
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
119
|
+
### Available Parameters
|
|
120
|
+
|
|
121
|
+
| parameter | default | options | description |
|
|
122
|
+
| --- | --- | --- | --- |
|
|
123
|
+
| locking_name_field | `:locking_name` | any field name | field where name of locking is storing, must be of type `String` |
|
|
124
|
+
| 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` |
|
|
125
|
+
| lock_timeout | `5` | | within this time (in seconds) a document is considered as locked |
|
|
126
|
+
| 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 |
|
|
127
|
+
| maximum_backoff | `60.0` | | the highest timeout (in seconds) between retries to lock a document, reaching that value `#with_lock` method raises `Mongoid::Locker::Errors::DocumentCouldNotGetLock` |
|
|
128
|
+
| 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 |
|
|
129
|
+
| locking_name_generator | `:secure_locking_name` | [custom generator](#custom-backoff_algorithm-and-locking_name_generator) | generator used to generate unique name of a lock |
|
|
110
130
|
|
|
111
131
|
For instances of a class where `Mongoid::Locker` is included, all parameters of a class are available for reading.
|
|
132
|
+
|
|
112
133
|
```ruby
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
document.lock_timeout
|
|
135
|
+
# => 5
|
|
115
136
|
```
|
|
116
137
|
|
|
117
|
-
### Custom
|
|
138
|
+
### Custom `backoff_algorithm` and `locking_name_generator`
|
|
139
|
+
|
|
118
140
|
A method which is defined in `Mongoid::Locker` are available in a class where it is included.
|
|
119
141
|
|
|
120
142
|
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:
|
|
143
|
+
|
|
121
144
|
```ruby
|
|
122
|
-
|
|
145
|
+
{ retries: Infinity, reload: true, attempt: 0, locking_name: '71c1ccd4-72d9-4a83-bbed-adf65803bd5d' }
|
|
123
146
|
```
|
|
124
147
|
|
|
125
|
-
A custom backoff
|
|
148
|
+
A custom backoff algorithm **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.
|
|
149
|
+
|
|
126
150
|
```ruby
|
|
127
151
|
Mongoid::Locker.configure do |config|
|
|
128
152
|
config.backoff_algorithm = :custom_backoff
|
|
@@ -138,6 +162,7 @@ end
|
|
|
138
162
|
```
|
|
139
163
|
|
|
140
164
|
A custom locking name generator **must return** a string to secure uniqueness name of locking.
|
|
165
|
+
|
|
141
166
|
```ruby
|
|
142
167
|
class User
|
|
143
168
|
include Mongoid::Document
|
|
@@ -151,13 +176,38 @@ class User
|
|
|
151
176
|
def self.custom_locking_name(_doc, _opts)
|
|
152
177
|
SecureRandom.uuid
|
|
153
178
|
end
|
|
179
|
+
end
|
|
154
180
|
```
|
|
155
181
|
|
|
156
182
|
## Testing with RSpec
|
|
183
|
+
|
|
157
184
|
Please see examples in [test_examples_spec.rb](spec/test_examples_spec.rb) file.
|
|
158
185
|
|
|
186
|
+
### Sharded Collections
|
|
187
|
+
|
|
188
|
+
Locking is integration-tested through a real `mongos` router with collections sharded by ranged and hashed `_id` keys. These tests cover acquiring and releasing locks, contention, expired locks, and exceptions. They use a single-shard cluster; they do not test chunk migrations or arbitrary non-`_id` shard keys.
|
|
189
|
+
|
|
190
|
+
To run the sharding tests locally, start the disposable cluster and wait until its shard is registered:
|
|
191
|
+
|
|
192
|
+
```sh
|
|
193
|
+
docker run -d --name locker-sharding -p 127.0.0.1:27028:27017 \
|
|
194
|
+
-v "$PWD/spec/integration/sharding/start.sh:/start.sh:ro" \
|
|
195
|
+
mongo:8.0 bash /start.sh
|
|
196
|
+
docker exec locker-sharding mongosh --quiet --eval 'db.adminCommand({listShards:1})'
|
|
197
|
+
SHARDED_MONGODB_URI=mongodb://localhost:27028/mongoid_locker_sharding_test \
|
|
198
|
+
bundle exec rspec spec/integration/sharding
|
|
199
|
+
docker stop locker-sharding
|
|
200
|
+
docker rm locker-sharding
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Use a dedicated test database: these tests drop and recreate their collection. Without `SHARDED_MONGODB_URI`, they are skipped by the normal suite. CI starts the cluster and runs them separately on MongoDB 6.0 and 8.0.
|
|
204
|
+
|
|
205
|
+
## Contributing
|
|
206
|
+
|
|
207
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md), [CHANGELOG.md](CHANGELOG.md), [UPGRADING.md](UPGRADING.md), and [RELEASING.md](RELEASING.md).
|
|
208
|
+
|
|
159
209
|
## Copyright & License
|
|
160
210
|
|
|
161
211
|
Copyright (c) 2012-2020 Aidan Feldman & Contributors
|
|
162
212
|
|
|
163
|
-
MIT License, see [LICENSE](LICENSE.txt) for more information.
|
|
213
|
+
MIT License, see [LICENSE.txt](LICENSE.txt) for more information.
|
data/RELEASING.md
CHANGED
|
@@ -1,67 +1,35 @@
|
|
|
1
|
-
Releasing Mongoid
|
|
2
|
-
=========================
|
|
1
|
+
# Releasing Mongoid-Locker
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
Releases use [ruby-gem-release](https://github.com/dblock/ruby-gem-release) 0.9.0 through a manually dispatched [Release workflow](.github/workflows/release.yml). Keep the `ruby-gem-release` gem in [Gemfile](Gemfile) and the reusable workflow in `release.yml` pinned to the same version. The workflow publishes through RubyGems Trusted Publishing, so no RubyGems API key or one-time password is needed. It only runs from `master` in `mongoid/mongoid-locker`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
## One-Time Setup
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
Before the first automated release, a maintainer must:
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
Check that the last build succeeded in [GitHub Actions](https://github.com/mongoid/mongoid-locker/actions) for all supported platforms.
|
|
16
|
-
|
|
17
|
-
Check the version, if needed modify [lib/mongoid/locker/version.rb](lib/mongoid/locker/version.rb).
|
|
18
|
-
|
|
19
|
-
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
|
|
20
|
-
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.4.0`).
|
|
21
|
-
|
|
22
|
-
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
### 0.4.0 (2014-01-27)
|
|
26
|
-
```
|
|
9
|
+
1. Create the GitHub environment `release` in `mongoid/mongoid-locker`, for example with `gh api --method PUT repos/mongoid/mongoid-locker/environments/release`, and restrict its deployment branches to `master`. Add required reviewers to require maintainer approval before publication.
|
|
10
|
+
2. At [mongoid-locker's trusted publishers](https://rubygems.org/gems/mongoid-locker/trusted_publishers), add a GitHub Actions publisher with repository owner `mongoid`, repository `mongoid-locker`, workflow filename `release.yml`, environment `release`, and the separate workflow repository owner `dblock` and repository `ruby-gem-release`.
|
|
11
|
+
3. Allow GitHub Actions to push release commits and `v*` tags to `master`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).
|
|
27
12
|
|
|
28
|
-
|
|
13
|
+
Verify the setup without publishing with a [dry run](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#dry-run), which never edits files, builds, pushes, or publishes:
|
|
29
14
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
git add CHANGELOG.md lib/mongoid-locker/version.rb
|
|
34
|
-
git commit -m "Preparing for release, 0.4.0."
|
|
35
|
-
git push origin master
|
|
15
|
+
```sh
|
|
16
|
+
gh workflow run release.yml --repo mongoid/mongoid-locker --ref master -f dry-run=true
|
|
36
17
|
```
|
|
37
18
|
|
|
38
|
-
|
|
19
|
+
## Prepare
|
|
39
20
|
|
|
40
|
-
|
|
41
|
-
$ bundle exec rake release
|
|
42
|
-
|
|
43
|
-
mongoid-locker 0.4.0 built to pkg/mongoid-locker-0.4.0.gem.
|
|
44
|
-
Tagged v0.4.0.
|
|
45
|
-
Pushed git commits and tags.
|
|
46
|
-
Pushed mongoid-locker 0.4.0 to rubygems.org.
|
|
47
|
-
```
|
|
21
|
+
Start with a clean, up-to-date `master` and verify that the latest [CI checks](https://github.com/mongoid/mongoid-locker/actions) pass. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/mongoid/locker/version.rb](lib/mongoid/locker/version.rb) and the matching `(Next)` heading in [CHANGELOG.md](CHANGELOG.md), and change both in a pull request if needed, or pass a `version` override when dispatching. The workflow dates the `(Next)` heading using `YYYY/MM/DD` and removes the `* Your contribution here.` placeholder; a section without notes cannot be released.
|
|
48
22
|
|
|
49
|
-
|
|
23
|
+
Release automation requires MRI Ruby 3.3 or newer; the release dependency and tasks are skipped on older Ruby versions and JRuby. Release specs in [spec/release](spec/release) run the actual release tasks against a local fixture with the [ruby-gem-release RSpec helpers](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/testing.md), without contacting RubyGems or GitHub.
|
|
50
24
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
|
25
|
+
## Publish
|
|
54
26
|
|
|
27
|
+
```sh
|
|
28
|
+
gh workflow run release.yml --repo mongoid/mongoid-locker --ref master
|
|
55
29
|
```
|
|
56
|
-
### 0.4.1 (Next)
|
|
57
30
|
|
|
58
|
-
|
|
59
|
-
```
|
|
31
|
+
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `master` while it runs. The workflow prepares the release commit, starts MongoDB 8.0, runs lint and specs on Ruby 3.3, builds the gem, preserves recovery artifacts, publishes to RubyGems, pushes the release commit and `v` tag, and creates a GitHub Release with the changelog notes and the gem attached. It then increments the patch version, adds a new `(Next)` section, and pushes the next development commit. Verify the published version on [RubyGems](https://rubygems.org/gems/mongoid-locker), the tag, the [GitHub Release](https://github.com/mongoid/mongoid-locker/releases), and the next development commit.
|
|
60
32
|
|
|
61
|
-
|
|
33
|
+
## Recover a Partial Release
|
|
62
34
|
|
|
63
|
-
|
|
64
|
-
git add CHANGELOG.md lib/mongoid-locker/version.rb
|
|
65
|
-
git commit -m "Preparing for next release, 0.4.1."
|
|
66
|
-
git push origin master
|
|
67
|
-
```
|
|
35
|
+
Inspect the failed run, RubyGems, remote commits and tags, and the GitHub Release before retrying. Publication may have succeeded even if a later step failed. Never move a published tag or republish a version with different contents. Use the run's retained recovery artifacts and the upstream [recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts).
|
data/Rakefile
CHANGED
|
@@ -3,6 +3,18 @@
|
|
|
3
3
|
require 'rubygems'
|
|
4
4
|
require 'bundler/setup'
|
|
5
5
|
require 'bundler/gem_tasks'
|
|
6
|
+
|
|
7
|
+
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
8
|
+
Gem.loaded_specs.key?('ruby-gem-release')
|
|
9
|
+
require_relative 'script/release'
|
|
10
|
+
MongoidLockerRelease.workflow.install_tasks
|
|
11
|
+
|
|
12
|
+
%w[release release:rubygem_push release:source_control_push].each do |name|
|
|
13
|
+
Rake::Task[name].clear
|
|
14
|
+
desc 'Disabled; releases run through GitHub Actions, see RELEASING.md'
|
|
15
|
+
task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
6
18
|
require 'rake'
|
|
7
19
|
|
|
8
20
|
require 'rspec/core'
|
|
@@ -11,7 +23,14 @@ RSpec::Core::RakeTask.new(:spec) do |spec|
|
|
|
11
23
|
spec.pattern = FileList['spec/**/*_spec.rb']
|
|
12
24
|
end
|
|
13
25
|
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
lint = RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
27
|
+
Gem.loaded_specs.key?('rubocop')
|
|
28
|
+
if lint
|
|
29
|
+
require 'rubocop/rake_task'
|
|
30
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
31
|
+
|
|
32
|
+
desc 'Lint Ruby, Markdown, YAML, and spelling'
|
|
33
|
+
task lint: :rubocop
|
|
34
|
+
end
|
|
16
35
|
|
|
17
|
-
task default: %i[rubocop spec]
|
|
36
|
+
task default: lint ? %i[rubocop spec] : %i[spec]
|
data/UPGRADING.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
## Upgrading Mongoid-Locker
|
|
2
2
|
|
|
3
|
-
## Upgrading
|
|
3
|
+
## Upgrading To 2.0.0
|
|
4
4
|
|
|
5
|
-
Mongoid-Locker supports only `5`, `6` and `7` versions of Mongoid.
|
|
6
|
-
Since this version `Mongoid::Locker` uses unique name of locking and time is set by MongoDB. `Mongoid::Locker` no longer uses `locked_until` field and this field may be deleted with `User.all.unset(:locked_until)`. You must define new `locking_name` field of `String` type.
|
|
5
|
+
Mongoid-Locker supports only `5`, `6` and `7` versions of Mongoid. Since this version `Mongoid::Locker` uses unique name of locking and time is set by MongoDB. `Mongoid::Locker` no longer uses `locked_until` field and this field may be deleted with `User.all.unset(:locked_until)`. You must define new `locking_name` field of `String` type.
|
|
7
6
|
|
|
8
7
|
```ruby
|
|
9
8
|
class User
|
|
@@ -15,10 +14,9 @@ class User
|
|
|
15
14
|
end
|
|
16
15
|
```
|
|
17
16
|
|
|
18
|
-
The options `:timeout` and `retry_sleep` of `#with_lock` method was deprecated and have no effect. For details see [RubyDoc.info](https://www.rubydoc.info/gems/mongoid-locker/2.0.0/Mongoid/Locker#with_lock-instance_method).
|
|
19
|
-
If you handle `Mongoid::Locker::LockError` error then this error should be renamed to `Mongoid::Locker::Errors::DocumentCouldNotGetLock`.
|
|
17
|
+
The options `:timeout` and `retry_sleep` of `#with_lock` method was deprecated and have no effect. For details see [RubyDoc.info](https://www.rubydoc.info/gems/mongoid-locker/2.0.0/Mongoid/Locker#with_lock-instance_method). If you handle `Mongoid::Locker::LockError` error then this error should be renamed to `Mongoid::Locker::Errors::DocumentCouldNotGetLock`.
|
|
20
18
|
|
|
21
|
-
### Upgrading
|
|
19
|
+
### Upgrading To 1.0.0
|
|
22
20
|
|
|
23
21
|
`Mongoid::Locker` no longer defines `locked_at` and `locked_until` fields when included. You must define these fields manually.
|
|
24
22
|
|
data/lib/mongoid/locker.rb
CHANGED
|
@@ -45,7 +45,7 @@ module Mongoid
|
|
|
45
45
|
# @param opts [Hash] (see #with_lock)
|
|
46
46
|
# @return [Float]
|
|
47
47
|
def exponential_backoff(_doc, opts)
|
|
48
|
-
2**opts[:attempt] + rand
|
|
48
|
+
(2**opts[:attempt]) + rand
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
# Returns time in seconds remaining to complete the lock of the provided document. Makes requests to the database.
|
|
@@ -115,7 +115,9 @@ module Mongoid
|
|
|
115
115
|
klass.locking_name_generator = locking_name_generator
|
|
116
116
|
|
|
117
117
|
klass.delegate(*MODULE_METHODS, to: :class)
|
|
118
|
-
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map
|
|
118
|
+
klass.singleton_class.delegate(*(methods(false) - MODULE_METHODS.flat_map do |method|
|
|
119
|
+
[method, :"#{method}="]
|
|
120
|
+
end - %i[included reset! configure]), to: self)
|
|
119
121
|
end
|
|
120
122
|
end
|
|
121
123
|
|
|
@@ -202,7 +204,10 @@ module Mongoid
|
|
|
202
204
|
# @param locking_name_generator [Symbol]
|
|
203
205
|
def locker(**params)
|
|
204
206
|
invalid_parameters = params.keys - Mongoid::Locker.singleton_class.const_get('MODULE_METHODS')
|
|
205
|
-
|
|
207
|
+
unless invalid_parameters.empty?
|
|
208
|
+
raise Mongoid::Locker::Errors::InvalidParameter.new(self.class,
|
|
209
|
+
invalid_parameters.first)
|
|
210
|
+
end
|
|
206
211
|
|
|
207
212
|
params.each_pair do |key, value|
|
|
208
213
|
send("#{key}=", value)
|
|
@@ -271,7 +276,10 @@ module Mongoid
|
|
|
271
276
|
opts[:attempt] += 1
|
|
272
277
|
delay = self.class.send(backoff_algorithm, self, opts)
|
|
273
278
|
|
|
274
|
-
|
|
279
|
+
if delay >= maximum_backoff || opts[:attempt] >= opts[:retries]
|
|
280
|
+
raise Errors::DocumentCouldNotGetLock.new(self.class,
|
|
281
|
+
id)
|
|
282
|
+
end
|
|
275
283
|
|
|
276
284
|
sleep delay
|
|
277
285
|
end
|
data/mongoid-locker.gemspec
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
require 'mongoid/locker/version'
|
|
3
|
+
require_relative 'lib/mongoid/locker/version'
|
|
6
4
|
|
|
7
5
|
Gem::Specification.new do |s|
|
|
8
6
|
s.name = 'mongoid-locker'
|
|
@@ -19,4 +17,5 @@ Gem::Specification.new do |s|
|
|
|
19
17
|
s.require_paths = ['lib']
|
|
20
18
|
|
|
21
19
|
s.add_dependency 'mongoid', '>= 5.0', '< 10'
|
|
20
|
+
s.metadata['rubygems_mfa_required'] = 'true'
|
|
22
21
|
end
|
data/script/release.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruby-gem-release/changelog'
|
|
4
|
+
require 'ruby-gem-release/workflow/ruby_gem'
|
|
5
|
+
|
|
6
|
+
# Builds the ruby-gem-release workflow used by the Rakefile, the Release GitHub Actions workflow, and spec/release.
|
|
7
|
+
module MongoidLockerRelease
|
|
8
|
+
def self.workflow(**options)
|
|
9
|
+
RubyGemRelease::Workflow::RubyGem.new(
|
|
10
|
+
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/mongoid/locker/version.rb', constant: 'VERSION'),
|
|
11
|
+
changelog: RubyGemRelease::Changelog::Intridea.new(
|
|
12
|
+
placeholder: '* Your contribution here.', date_format: '%Y-%m-%d'
|
|
13
|
+
),
|
|
14
|
+
**options
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mongoid-locker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Aidan Feldman
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date:
|
|
11
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: mongoid
|
|
@@ -37,13 +38,16 @@ executables: []
|
|
|
37
38
|
extensions: []
|
|
38
39
|
extra_rdoc_files: []
|
|
39
40
|
files:
|
|
41
|
+
- ".github/workflows/danger-comment.yml"
|
|
40
42
|
- ".github/workflows/danger.yml"
|
|
41
|
-
- ".github/workflows/
|
|
43
|
+
- ".github/workflows/lint.yml"
|
|
44
|
+
- ".github/workflows/release.yml"
|
|
42
45
|
- ".github/workflows/test.yml"
|
|
43
46
|
- ".gitignore"
|
|
44
47
|
- ".rspec"
|
|
45
48
|
- ".rubocop.yml"
|
|
46
49
|
- ".rubocop_todo.yml"
|
|
50
|
+
- ".spellcheck.txt"
|
|
47
51
|
- CHANGELOG.md
|
|
48
52
|
- CONTRIBUTING.md
|
|
49
53
|
- Dangerfile
|
|
@@ -61,10 +65,13 @@ files:
|
|
|
61
65
|
- lib/mongoid/locker/version.rb
|
|
62
66
|
- lib/mongoid/locker/wrapper.rb
|
|
63
67
|
- mongoid-locker.gemspec
|
|
68
|
+
- script/release.rb
|
|
64
69
|
homepage: https://github.com/mongoid/mongoid-locker
|
|
65
70
|
licenses:
|
|
66
71
|
- MIT
|
|
67
|
-
metadata:
|
|
72
|
+
metadata:
|
|
73
|
+
rubygems_mfa_required: 'true'
|
|
74
|
+
post_install_message:
|
|
68
75
|
rdoc_options: []
|
|
69
76
|
require_paths:
|
|
70
77
|
- lib
|
|
@@ -79,7 +86,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
86
|
- !ruby/object:Gem::Version
|
|
80
87
|
version: '0'
|
|
81
88
|
requirements: []
|
|
82
|
-
rubygems_version: 3.
|
|
89
|
+
rubygems_version: 3.5.22
|
|
90
|
+
signing_key:
|
|
83
91
|
specification_version: 4
|
|
84
92
|
summary: Document-level optimistic locking for MongoDB via Mongoid.
|
|
85
93
|
test_files: []
|