mongoid-locker 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +5 -5
- data/CHANGELOG.md +5 -0
- data/README.md +4 -1
- data/VERSION +1 -1
- data/lib/mongoid/locker/wrapper.rb +10 -40
- data/lib/mongoid/locker/wrapper2.rb +26 -0
- data/lib/mongoid/locker/wrapper3.rb +26 -0
- data/lib/mongoid/locker/wrapper4.rb +22 -0
- data/lib/mongoid/locker/wrapper5.rb +27 -0
- data/mongoid-locker.gemspec +8 -4
- data/spec/mongoid-locker_spec.rb +1 -1
- metadata +32 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15bbaa6b9c117c44fb72c5db1b1c6ec6a9019044
|
4
|
+
data.tar.gz: e0e4680415861b7ce27cba6bd3884a2cee123f3f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6cf643433841b6efba4ac548ace833fa50b6d4984cbc90c620ec1a38f5338943a181c372499394923d9386b96d328e1a8236904c3c94df7452c55a94badce0b
|
7
|
+
data.tar.gz: 27537644279ea4c3fb4299fcd1430c4b3d9f017222f29550965b2fdedbb7d9052cef223386f5136ead1b03989b8083650191157d3081fe77afca55228531d312
|
data/.rubocop_todo.yml
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2015-
|
2
|
+
# on 2015-10-21 11:03:44 -0400 using RuboCop version 0.29.1.
|
3
3
|
# The point is for the user to remove these configuration records
|
4
4
|
# one by one as the offenses are removed from the code base.
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
7
7
|
|
8
|
-
# Offense count:
|
8
|
+
# Offense count: 1
|
9
9
|
Metrics/AbcSize:
|
10
|
-
Max:
|
10
|
+
Max: 18
|
11
11
|
|
12
|
-
# Offense count:
|
12
|
+
# Offense count: 37
|
13
13
|
# Configuration parameters: AllowURI, URISchemes.
|
14
14
|
Metrics/LineLength:
|
15
15
|
Max: 184
|
16
16
|
|
17
|
-
# Offense count:
|
17
|
+
# Offense count: 3
|
18
18
|
# Configuration parameters: CountComments.
|
19
19
|
Metrics/MethodLength:
|
20
20
|
Max: 25
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.4 ([diff](https://github.com/afeld/mongoid-locker/compare/v0.3.4...master?w=1))
|
4
|
+
|
5
|
+
* fixed write concern for the lock record with Mongoid 5
|
6
|
+
* don't query the document in Mongoid 5, better performance when acquiring lock
|
7
|
+
|
3
8
|
## 0.3.3 ([diff](https://github.com/afeld/mongoid-locker/compare/v0.3.3...master?w=1))
|
4
9
|
|
5
10
|
* support Mongoid 5 - #36
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
-
# mongoid-locker
|
1
|
+
# mongoid-locker
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/mongoid-locker.svg)](http://badge.fury.io/rb/mongoid-locker)
|
3
|
+
[![Build Status](https://secure.travis-ci.org/afeld/mongoid-locker.svg?branch=master)](http://travis-ci.org/afeld/mongoid-locker)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/afeld/mongoid-locker.svg)](https://codeclimate.com/github/afeld/mongoid-locker)
|
2
5
|
|
3
6
|
Document-level locking for MongoDB via Mongoid. The need arose at [Jux](https://jux.com) from multiple processes on multiple servers trying to act upon the same document and stepping on each other's toes. Mongoid-Locker is an easy way to ensure only one process can perform a certain operation on a document at a time.
|
4
7
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.4
|
@@ -1,43 +1,13 @@
|
|
1
1
|
require 'mongoid/compatibility'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
def self.update(klass, query, setter)
|
14
|
-
if Mongoid::Compatibility::Version.mongoid5?
|
15
|
-
!klass.with(safe: true).collection.find(query).find_one_and_update(setter).nil?
|
16
|
-
elsif Mongoid::Compatibility::Version.mongoid2?
|
17
|
-
klass.collection.update(query, setter, safe: true)['n'] == 1
|
18
|
-
else
|
19
|
-
klass.with(safe: true).collection.find(query).update(setter)['n'] == 1
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
# Determine whether the provided document is locked in the database or not.
|
24
|
-
#
|
25
|
-
# @param [Class] The model instance
|
26
|
-
# @return [Time] The timestamp of when the document is locked until, nil if not locked.
|
27
|
-
def self.locked_until(doc)
|
28
|
-
existing_query = {
|
29
|
-
_id: doc.id,
|
30
|
-
locked_until: { '$exists' => true }
|
31
|
-
}
|
32
|
-
|
33
|
-
if Mongoid::Compatibility::Version.mongoid2?
|
34
|
-
existing = doc.class.collection.find_one(existing_query, fields: { locked_until: 1 })
|
35
|
-
existing ? existing['locked_until'] : nil
|
36
|
-
else
|
37
|
-
existing = doc.class.where(existing_query).limit(1).only(:locked_until).first
|
38
|
-
existing ? existing.locked_until : nil
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
3
|
+
if Mongoid::Compatibility::Version.mongoid5?
|
4
|
+
require 'mongoid/locker/wrapper5'
|
5
|
+
elsif Mongoid::Compatibility::Version.mongoid4?
|
6
|
+
require 'mongoid/locker/wrapper4'
|
7
|
+
elsif Mongoid::Compatibility::Version.mongoid3?
|
8
|
+
require 'mongoid/locker/wrapper3'
|
9
|
+
elsif Mongoid::Compatibility::Version.mongoid2?
|
10
|
+
require 'mongoid/locker/wrapper2'
|
11
|
+
else
|
12
|
+
fail 'incompatible Mongoid version'
|
43
13
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Locker
|
3
|
+
# Normalizes queries between various Mongoid versions.
|
4
|
+
module Wrapper
|
5
|
+
# Update the document for the provided Class matching the provided query with the provided setter.
|
6
|
+
#
|
7
|
+
# @param [Class] The model class
|
8
|
+
# @param [Hash] The Mongoid query
|
9
|
+
# @param [Hash] The Mongoid setter
|
10
|
+
# @return [Boolean] true if the document was successfully updated, false otherwise
|
11
|
+
def self.update(klass, query, setter)
|
12
|
+
klass.collection.update(query, setter, safe: true)['n'] == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
# Determine whether the provided document is locked in the database or not.
|
16
|
+
#
|
17
|
+
# @param [Class] The model instance
|
18
|
+
# @return [Time] The timestamp of when the document is locked until, nil if not locked.
|
19
|
+
def self.locked_until(doc)
|
20
|
+
existing_query = { _id: doc.id, locked_until: { '$exists' => true } }
|
21
|
+
existing = doc.class.collection.find_one(existing_query, fields: { locked_until: 1 })
|
22
|
+
existing ? existing['locked_until'] : nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Locker
|
3
|
+
# Normalizes queries between various Mongoid versions.
|
4
|
+
module Wrapper
|
5
|
+
# Update the document for the provided Class matching the provided query with the provided setter.
|
6
|
+
#
|
7
|
+
# @param [Class] The model class
|
8
|
+
# @param [Hash] The Mongoid query
|
9
|
+
# @param [Hash] The Mongoid setter
|
10
|
+
# @return [Boolean] true if the document was successfully updated, false otherwise
|
11
|
+
def self.update(klass, query, setter)
|
12
|
+
klass.with(safe: true).collection.find(query).update(setter)['n'] == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
# Determine whether the provided document is locked in the database or not.
|
16
|
+
#
|
17
|
+
# @param [Class] The model instance
|
18
|
+
# @return [Time] The timestamp of when the document is locked until, nil if not locked.
|
19
|
+
def self.locked_until(doc)
|
20
|
+
existing_query = { _id: doc.id, locked_until: { '$exists' => true } }
|
21
|
+
existing = doc.class.where(existing_query).limit(1).only(:locked_until).first
|
22
|
+
existing ? existing.locked_until : nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Locker
|
3
|
+
# Normalizes queries between various Mongoid versions.
|
4
|
+
module Wrapper
|
5
|
+
# Update the document for the provided Class matching the provided query with the provided setter.
|
6
|
+
#
|
7
|
+
# @param [Class] The model class
|
8
|
+
# @param [Hash] The Mongoid query
|
9
|
+
# @param [Hash] The Mongoid setter
|
10
|
+
# @return [Boolean] true if the document was successfully updated, false otherwise
|
11
|
+
def self.update(klass, query, setter)
|
12
|
+
klass.with(safe: true).collection.find(query).update(setter)['n'] == 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.locked_until(doc)
|
16
|
+
existing_query = { _id: doc.id, locked_until: { '$exists' => true } }
|
17
|
+
existing = doc.class.where(existing_query).limit(1).only(:locked_until).first
|
18
|
+
existing ? existing.locked_until : nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Locker
|
3
|
+
# Normalizes queries between various Mongoid versions.
|
4
|
+
module Wrapper
|
5
|
+
# Update the document for the provided Class matching the provided query with the provided setter.
|
6
|
+
#
|
7
|
+
# @param [Class] The model class
|
8
|
+
# @param [Hash] The Mongoid query
|
9
|
+
# @param [Hash] The Mongoid setter
|
10
|
+
# @return [Boolean] true if the document was successfully updated, false otherwise
|
11
|
+
def self.update(klass, query, setter)
|
12
|
+
rc = klass.with(write: { w: 1 }).collection.find(query).update_one(setter)
|
13
|
+
rc.ok? && rc.documents.first['n'] == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
# Determine whether the provided document is locked in the database or not.
|
17
|
+
#
|
18
|
+
# @param [Class] The model instance
|
19
|
+
# @return [Time] The timestamp of when the document is locked until, nil if not locked.
|
20
|
+
def self.locked_until(doc)
|
21
|
+
existing_query = { _id: doc.id, locked_until: { '$exists' => true } }
|
22
|
+
existing = doc.class.where(existing_query).limit(1).only(:locked_until).first
|
23
|
+
existing ? existing.locked_until : nil
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/mongoid-locker.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: mongoid-locker 0.3.
|
5
|
+
# stub: mongoid-locker 0.3.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "mongoid-locker"
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Aidan Feldman"]
|
14
|
-
s.date = "2015-
|
14
|
+
s.date = "2015-10-21"
|
15
15
|
s.description = "Allows multiple processes to operate on individual documents in MongoDB while ensuring that only one can act at a time."
|
16
16
|
s.email = "aidan.feldman@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -41,6 +41,10 @@ Gem::Specification.new do |s|
|
|
41
41
|
"lib/mongoid-locker.rb",
|
42
42
|
"lib/mongoid/locker.rb",
|
43
43
|
"lib/mongoid/locker/wrapper.rb",
|
44
|
+
"lib/mongoid/locker/wrapper2.rb",
|
45
|
+
"lib/mongoid/locker/wrapper3.rb",
|
46
|
+
"lib/mongoid/locker/wrapper4.rb",
|
47
|
+
"lib/mongoid/locker/wrapper5.rb",
|
44
48
|
"mongoid-locker.gemspec",
|
45
49
|
"spec/database2.yml",
|
46
50
|
"spec/database3.yml",
|
@@ -51,7 +55,7 @@ Gem::Specification.new do |s|
|
|
51
55
|
]
|
52
56
|
s.homepage = "http://github.com/afeld/mongoid-locker"
|
53
57
|
s.licenses = ["MIT"]
|
54
|
-
s.rubygems_version = "2.
|
58
|
+
s.rubygems_version = "2.4.5"
|
55
59
|
s.summary = "Document-level locking for MongoDB via Mongoid"
|
56
60
|
|
57
61
|
if s.respond_to? :specification_version then
|
data/spec/mongoid-locker_spec.rb
CHANGED
metadata
CHANGED
@@ -1,131 +1,131 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-locker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aidan Feldman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mongoid
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - <
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6.0'
|
20
|
-
- -
|
20
|
+
- - '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '2.8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - <
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '6.0'
|
30
|
-
- -
|
30
|
+
- - '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.8'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: mongoid-compatibility
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- -
|
37
|
+
- - '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
type: :runtime
|
41
41
|
prerelease: false
|
42
42
|
version_requirements: !ruby/object:Gem::Requirement
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - '>='
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '0'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '3.0'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
|
-
- -
|
58
|
+
- - ~>
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '3.0'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: bundler
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
|
-
- -
|
65
|
+
- - ~>
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '1.1'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '1.1'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: jeweler
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- -
|
79
|
+
- - ~>
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '1.8'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '1.8'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: guard-rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
|
-
- -
|
93
|
+
- - '>='
|
94
94
|
- !ruby/object:Gem::Version
|
95
95
|
version: '0'
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
|
-
- -
|
100
|
+
- - '>='
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: rb-fsevent
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - ~>
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: 0.9.1
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
|
-
- -
|
114
|
+
- - ~>
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 0.9.1
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: rake
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
120
120
|
requirements:
|
121
|
-
- -
|
121
|
+
- - '>='
|
122
122
|
- !ruby/object:Gem::Version
|
123
123
|
version: '0'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
|
-
- -
|
128
|
+
- - '>='
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
- !ruby/object:Gem::Dependency
|
@@ -151,11 +151,11 @@ extra_rdoc_files:
|
|
151
151
|
- LICENSE.txt
|
152
152
|
- README.md
|
153
153
|
files:
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
154
|
+
- .document
|
155
|
+
- .rspec
|
156
|
+
- .rubocop.yml
|
157
|
+
- .rubocop_todo.yml
|
158
|
+
- .travis.yml
|
159
159
|
- CHANGELOG.md
|
160
160
|
- CONTRIBUTING.md
|
161
161
|
- Gemfile
|
@@ -173,6 +173,10 @@ files:
|
|
173
173
|
- lib/mongoid-locker.rb
|
174
174
|
- lib/mongoid/locker.rb
|
175
175
|
- lib/mongoid/locker/wrapper.rb
|
176
|
+
- lib/mongoid/locker/wrapper2.rb
|
177
|
+
- lib/mongoid/locker/wrapper3.rb
|
178
|
+
- lib/mongoid/locker/wrapper4.rb
|
179
|
+
- lib/mongoid/locker/wrapper5.rb
|
176
180
|
- mongoid-locker.gemspec
|
177
181
|
- spec/database2.yml
|
178
182
|
- spec/database3.yml
|
@@ -190,17 +194,17 @@ require_paths:
|
|
190
194
|
- lib
|
191
195
|
required_ruby_version: !ruby/object:Gem::Requirement
|
192
196
|
requirements:
|
193
|
-
- -
|
197
|
+
- - '>='
|
194
198
|
- !ruby/object:Gem::Version
|
195
199
|
version: '0'
|
196
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
197
201
|
requirements:
|
198
|
-
- -
|
202
|
+
- - '>='
|
199
203
|
- !ruby/object:Gem::Version
|
200
204
|
version: '0'
|
201
205
|
requirements: []
|
202
206
|
rubyforge_project:
|
203
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.4.5
|
204
208
|
signing_key:
|
205
209
|
specification_version: 4
|
206
210
|
summary: Document-level locking for MongoDB via Mongoid
|