dynamoid_lockable 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yaml +21 -0
- data/.github/workflows/test.yaml +43 -0
- data/.rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-3-1-yml +5 -0
- data/.rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-yml +91 -0
- data/.rubocop.yml +6 -0
- data/.ruby-version +1 -0
- data/Appraisals +5 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +104 -62
- data/README.md +34 -2
- data/Rakefile +5 -3
- data/dynamoid_lockable.gemspec +6 -2
- data/lib/dynamoid_lockable/version.rb +3 -1
- data/lib/dynamoid_lockable.rb +20 -13
- metadata +68 -6
- data/.circleci/config.yml +0 -100
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b0b3e787459c6a8190477b630eef6609e8cffc382dc78ab8f6d177acf3a9b1d
|
4
|
+
data.tar.gz: a574dde6791710b38552e7da3704c46781f049133d67903795437e84b248dc13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57e2c50b5dc02f155e52a4865284f7f46c10b11108cd2457e227c79a16292930e17f0022693d2f411d33c49860b2a54d9ff5223d766249a0fcdd00043063675b
|
7
|
+
data.tar.gz: d181571a64c68c7c02291eac76fd2ed9ea867e58877c95212abb593f58134370b2584bd5ac54f98b07718c6659a668377f2c10638d7f6bf0ac42bd9a44d8f3f4
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: 'Lint'
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
run-rubocop:
|
7
|
+
name: Lint code
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
rubyVersion: ["2.7.6"]
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
- uses: ruby/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: ${{ matrix.rubyVersion }}
|
18
|
+
bundler-cache: true
|
19
|
+
cache-version: "${{ matrix.rubyVersion }}-0"
|
20
|
+
- name: Run RuboCop
|
21
|
+
run: bundle exec rubocop
|
@@ -0,0 +1,43 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: push
|
4
|
+
|
5
|
+
env:
|
6
|
+
ImageOS: ubuntu18
|
7
|
+
NOKOGIRI_USE_SYSTEM_LIBRARIES: true
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
run-tests:
|
11
|
+
name: Test code
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
strategy:
|
14
|
+
fail-fast: false
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- 3.0.4
|
18
|
+
- 2.7.6
|
19
|
+
- 3.1.2
|
20
|
+
services:
|
21
|
+
dynamodb:
|
22
|
+
image: amazon/dynamodb-local
|
23
|
+
ports:
|
24
|
+
- 8000/tcp
|
25
|
+
steps:
|
26
|
+
- uses: actions/checkout@v2
|
27
|
+
- uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
bundler-cache: true
|
31
|
+
cache-version: ${{ matrix.ruby }}-0
|
32
|
+
- name: Run RSpec
|
33
|
+
env:
|
34
|
+
AWS_ACCESS_KEY_ID: asdf
|
35
|
+
AWS_SECRET_ACCESS_KEY: asdf
|
36
|
+
CI: true
|
37
|
+
DYNAMODB_HOST: http://localhost:${{job.services.dynamodb.ports[8000]}}/
|
38
|
+
run: bundle exec rspec
|
39
|
+
- name: Coveralls
|
40
|
+
uses: coverallsapp/github-action@v1.1.2
|
41
|
+
continue-on-error: true
|
42
|
+
with:
|
43
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
data/.rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-yml
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
AllCops:
|
2
|
+
Exclude:
|
3
|
+
- Makefile
|
4
|
+
- vendor/**/*
|
5
|
+
- bin/**/*
|
6
|
+
|
7
|
+
Layout/EndOfLine:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/DateTime:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/Documentation:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Lint/Debugger:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Style/FrozenStringLiteralComment:
|
20
|
+
Enabled: true
|
21
|
+
EnforcedStyle: always
|
22
|
+
|
23
|
+
Style/TrailingCommaInHashLiteral:
|
24
|
+
Enabled: true
|
25
|
+
EnforcedStyleForMultiline: comma
|
26
|
+
|
27
|
+
Style/TrailingCommaInArrayLiteral:
|
28
|
+
Enabled: true
|
29
|
+
EnforcedStyleForMultiline: comma
|
30
|
+
|
31
|
+
Style/TrailingCommaInArguments:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyleForMultiline: comma
|
34
|
+
|
35
|
+
Lint/UnusedMethodArgument:
|
36
|
+
AllowUnusedKeywordArguments: true
|
37
|
+
|
38
|
+
Layout/LineLength:
|
39
|
+
Enabled: true
|
40
|
+
Max: 280
|
41
|
+
IgnoreCopDirectives: true
|
42
|
+
IgnoredPatterns: ['\A#', '\A\s*sig { .* }\Z']
|
43
|
+
Exclude:
|
44
|
+
- '**/*_pb.rb'
|
45
|
+
|
46
|
+
Metrics/AbcSize:
|
47
|
+
Enabled: true
|
48
|
+
Max: 48
|
49
|
+
|
50
|
+
Metrics/CyclomaticComplexity:
|
51
|
+
Max: 9
|
52
|
+
|
53
|
+
Metrics/MethodLength:
|
54
|
+
Enabled: true
|
55
|
+
Max: 32
|
56
|
+
|
57
|
+
Layout/ParameterAlignment:
|
58
|
+
Enabled: true
|
59
|
+
EnforcedStyle: with_fixed_indentation
|
60
|
+
|
61
|
+
Naming/MethodParameterName:
|
62
|
+
Enabled: true
|
63
|
+
AllowedNames: ['io', 'id', 'to', 'by', 'on', 'in', 'at', '_'] # Defaults + _
|
64
|
+
|
65
|
+
Layout/MultilineMethodCallIndentation:
|
66
|
+
Enabled: true
|
67
|
+
EnforcedStyle: indented
|
68
|
+
|
69
|
+
Style/ParallelAssignment:
|
70
|
+
Enabled: true
|
71
|
+
|
72
|
+
Metrics/ClassLength:
|
73
|
+
Max: 240
|
74
|
+
|
75
|
+
Metrics/BlockLength:
|
76
|
+
Max: 30
|
77
|
+
Exclude:
|
78
|
+
- spec/**/*.rb
|
79
|
+
- '**/*_pb.rb'
|
80
|
+
|
81
|
+
Metrics/ParameterLists:
|
82
|
+
Max: 6
|
83
|
+
|
84
|
+
Lint/AmbiguousBlockAssociation:
|
85
|
+
Exclude:
|
86
|
+
- spec/**/*.rb
|
87
|
+
|
88
|
+
Style/BlockDelimiters:
|
89
|
+
Enabled: true
|
90
|
+
Exclude:
|
91
|
+
- spec/**/*
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.6
|
data/Appraisals
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
appraise
|
3
|
-
gem
|
3
|
+
appraise 'dynamoid-3.4' do
|
4
|
+
gem 'dynamoid', '~> 3.4.0'
|
4
5
|
end
|
5
6
|
|
6
|
-
appraise
|
7
|
-
gem
|
7
|
+
appraise 'dynamoid-latest' do
|
8
|
+
gem 'dynamoid', '~> 3.0'
|
8
9
|
end
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,85 +1,124 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamoid_lockable (1.
|
4
|
+
dynamoid_lockable (1.1.0)
|
5
5
|
dynamoid_advanced_where (>= 1.0.1, < 2.0)
|
6
|
+
rexml
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activemodel (
|
11
|
-
activesupport (=
|
12
|
-
activesupport (
|
11
|
+
activemodel (7.0.3.1)
|
12
|
+
activesupport (= 7.0.3.1)
|
13
|
+
activesupport (7.0.3.1)
|
13
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
-
i18n (>=
|
15
|
-
minitest (
|
16
|
-
tzinfo (~>
|
17
|
-
|
18
|
-
appraisal (2.2.0)
|
15
|
+
i18n (>= 1.6, < 2)
|
16
|
+
minitest (>= 5.1)
|
17
|
+
tzinfo (~> 2.0)
|
18
|
+
appraisal (2.4.1)
|
19
19
|
bundler
|
20
20
|
rake
|
21
21
|
thor (>= 0.14.0)
|
22
|
-
|
23
|
-
aws-
|
24
|
-
aws-
|
25
|
-
|
26
|
-
aws-
|
22
|
+
ast (2.4.2)
|
23
|
+
aws-eventstream (1.2.0)
|
24
|
+
aws-partitions (1.618.0)
|
25
|
+
aws-sdk-core (3.132.0)
|
26
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
27
|
+
aws-partitions (~> 1, >= 1.525.0)
|
27
28
|
aws-sigv4 (~> 1.1)
|
28
|
-
jmespath (~> 1.
|
29
|
-
aws-sdk-dynamodb (1.
|
30
|
-
aws-sdk-core (~> 3, >= 3.
|
29
|
+
jmespath (~> 1, >= 1.6.1)
|
30
|
+
aws-sdk-dynamodb (1.75.0)
|
31
|
+
aws-sdk-core (~> 3, >= 3.127.0)
|
31
32
|
aws-sigv4 (~> 1.1)
|
32
|
-
aws-sigv4 (1.1
|
33
|
-
aws-eventstream (~> 1
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
aws-sigv4 (1.5.1)
|
34
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
35
|
+
backports (3.23.0)
|
36
|
+
binding_of_caller (1.0.0)
|
37
|
+
debug_inspector (>= 0.0.1)
|
38
|
+
coderay (1.1.3)
|
39
|
+
concurrent-ruby (1.1.10)
|
40
|
+
debug_inspector (1.1.0)
|
41
|
+
deep-cover (1.1.0)
|
42
|
+
deep-cover-core (= 1.1.0)
|
43
|
+
highline
|
44
|
+
thor (>= 0.20.3)
|
45
|
+
with_progress
|
46
|
+
deep-cover-core (1.1.0)
|
47
|
+
backports (>= 3.11.0)
|
48
|
+
binding_of_caller
|
49
|
+
parser (>= 2.5)
|
50
|
+
pry
|
51
|
+
term-ansicolor
|
52
|
+
terminal-table
|
53
|
+
diff-lcs (1.5.0)
|
54
|
+
docile (1.4.0)
|
55
|
+
dynamoid (3.7.1)
|
43
56
|
activemodel (>= 4)
|
44
|
-
aws-sdk-dynamodb (~> 1)
|
57
|
+
aws-sdk-dynamodb (~> 1.0)
|
45
58
|
concurrent-ruby (>= 1.0)
|
46
|
-
|
47
|
-
dynamoid_advanced_where (1.0.1)
|
59
|
+
dynamoid_advanced_where (1.3.0)
|
48
60
|
dynamoid (>= 3.2, < 4)
|
49
|
-
|
61
|
+
highline (2.0.3)
|
62
|
+
i18n (1.12.0)
|
50
63
|
concurrent-ruby (~> 1.0)
|
51
|
-
jmespath (1.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
64
|
+
jmespath (1.6.1)
|
65
|
+
method_source (1.0.0)
|
66
|
+
minitest (5.16.2)
|
67
|
+
parallel (1.22.1)
|
68
|
+
parser (3.1.2.0)
|
69
|
+
ast (~> 2.4.1)
|
70
|
+
pry (0.14.1)
|
71
|
+
coderay (~> 1.1)
|
72
|
+
method_source (~> 1.0)
|
73
|
+
rainbow (3.1.1)
|
59
74
|
rake (12.3.3)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
rspec-
|
64
|
-
|
65
|
-
rspec-
|
66
|
-
rspec-
|
75
|
+
regexp_parser (2.5.0)
|
76
|
+
rexml (3.2.5)
|
77
|
+
rspec (3.11.0)
|
78
|
+
rspec-core (~> 3.11.0)
|
79
|
+
rspec-expectations (~> 3.11.0)
|
80
|
+
rspec-mocks (~> 3.11.0)
|
81
|
+
rspec-core (3.11.0)
|
82
|
+
rspec-support (~> 3.11.0)
|
83
|
+
rspec-expectations (3.11.0)
|
67
84
|
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
-
rspec-support (~> 3.
|
69
|
-
rspec-mocks (3.
|
85
|
+
rspec-support (~> 3.11.0)
|
86
|
+
rspec-mocks (3.11.1)
|
70
87
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
|
-
rspec-support (~> 3.
|
72
|
-
rspec-support (3.
|
73
|
-
|
88
|
+
rspec-support (~> 3.11.0)
|
89
|
+
rspec-support (3.11.0)
|
90
|
+
rubocop (1.30.1)
|
91
|
+
parallel (~> 1.10)
|
92
|
+
parser (>= 3.1.0.0)
|
93
|
+
rainbow (>= 2.2.2, < 4.0)
|
94
|
+
regexp_parser (>= 1.8, < 3.0)
|
95
|
+
rexml (>= 3.2.5, < 4.0)
|
96
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
97
|
+
ruby-progressbar (~> 1.7)
|
98
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
99
|
+
rubocop-ast (1.18.0)
|
100
|
+
parser (>= 3.1.1.0)
|
101
|
+
ruby-progressbar (1.11.0)
|
102
|
+
simplecov (0.21.2)
|
74
103
|
docile (~> 1.1)
|
75
|
-
simplecov-html (~> 0.11
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
104
|
+
simplecov-html (~> 0.11)
|
105
|
+
simplecov_json_formatter (~> 0.1)
|
106
|
+
simplecov-html (0.12.3)
|
107
|
+
simplecov-lcov (0.8.0)
|
108
|
+
simplecov_json_formatter (0.1.4)
|
109
|
+
sync (0.5.0)
|
110
|
+
term-ansicolor (1.7.1)
|
111
|
+
tins (~> 1.0)
|
112
|
+
terminal-table (3.0.2)
|
113
|
+
unicode-display_width (>= 1.1.1, < 3)
|
114
|
+
thor (1.2.1)
|
115
|
+
tins (1.31.1)
|
116
|
+
sync
|
117
|
+
tzinfo (2.0.5)
|
118
|
+
concurrent-ruby (~> 1.0)
|
119
|
+
unicode-display_width (2.1.0)
|
120
|
+
with_progress (1.0.1)
|
121
|
+
ruby-progressbar (~> 1.4)
|
83
122
|
|
84
123
|
PLATFORMS
|
85
124
|
ruby
|
@@ -87,11 +126,14 @@ PLATFORMS
|
|
87
126
|
|
88
127
|
DEPENDENCIES
|
89
128
|
appraisal
|
90
|
-
|
129
|
+
deep-cover
|
91
130
|
dynamoid_lockable!
|
92
131
|
pry
|
93
132
|
rake (~> 12)
|
94
133
|
rspec (~> 3)
|
134
|
+
rubocop
|
135
|
+
simplecov
|
136
|
+
simplecov-lcov (~> 0.8.0)
|
95
137
|
|
96
138
|
BUNDLED WITH
|
97
|
-
2.
|
139
|
+
2.3.12
|
data/README.md
CHANGED
@@ -18,7 +18,7 @@ Or install it yourself as:
|
|
18
18
|
$ gem install dynamoid_lockable
|
19
19
|
|
20
20
|
## Usage
|
21
|
-
```
|
21
|
+
```ruby
|
22
22
|
class MyModel
|
23
23
|
include Dynamoid::Document
|
24
24
|
include DynamoidLockable
|
@@ -55,7 +55,7 @@ thing.lock(:importing)
|
|
55
55
|
thing.lock(:importing) # No error
|
56
56
|
|
57
57
|
Thread.new do
|
58
|
-
thing.lock(:importing) # Error:
|
58
|
+
thing.lock(:importing) # Error: DynamoidLockable::CouldNotAcquireLock
|
59
59
|
end
|
60
60
|
```
|
61
61
|
|
@@ -67,6 +67,38 @@ A note on the options:
|
|
67
67
|
* If unable to obtain a lock, `DynamoidLockable::CouldNotAcquireLock` is raised
|
68
68
|
* If unable to obtain to release a lock, `DynamoidLockable::CouldNotUnlock` is raised
|
69
69
|
|
70
|
+
## Testing Lockable Items
|
71
|
+
|
72
|
+
By default when calling `perform_with_lock`, IDs used for locks are based on a unique ID assigned to each thread. If you want to write tests in your application to ensure locking is behaving how you desire, there are two ways. The easiest way is to simply manually call `lock` with a specified locker_name. Example:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
describe 'locking works' do
|
76
|
+
before do
|
77
|
+
my_object.lock(:thing_in_progress, locker_name: 'tEsT_lOcKeR_nAmE')
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'never calls some method that needs to acquire the lock' do
|
81
|
+
expect(job).not_to receive(:my_locked_method!)
|
82
|
+
job.perform
|
83
|
+
end
|
84
|
+
end
|
85
|
+
```
|
86
|
+
|
87
|
+
The other way is to use `perform_with_lock` in an 'around' block, and then spawn a new thread. Example:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
describe 'locking works' do
|
91
|
+
around do |ex|
|
92
|
+
my_object.perform_with_lock(:thing_in_progress) { ex.run }
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'never calls some method that needs to acquire the lock' do
|
96
|
+
expect(job).not_to receive(:my_locked_method!)
|
97
|
+
Thread.new { job.perform }.join # spawn a thread, call your job method, then join the thread
|
98
|
+
end
|
99
|
+
end
|
100
|
+
```
|
101
|
+
|
70
102
|
## Development
|
71
103
|
|
72
104
|
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.
|
data/Rakefile
CHANGED
data/dynamoid_lockable.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
spec.summary = 'Lock your Dynamoid records for only your use'
|
12
12
|
spec.description = 'Uses atomic writes to DynamoDB to ensure you hold an exclusive lock on your records'
|
13
13
|
spec.homepage = 'https://github.com/GetTerminus/dynamoid_lockable'
|
14
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
15
15
|
|
16
16
|
spec.metadata['allowed_push_host'] = 'https://www.rubygems.org'
|
17
17
|
|
@@ -30,8 +30,12 @@ Gem::Specification.new do |spec|
|
|
30
30
|
|
31
31
|
spec.add_runtime_dependency 'dynamoid_advanced_where', '>= 1.0.1', '< 2.0'
|
32
32
|
|
33
|
+
spec.add_dependency 'rexml'
|
33
34
|
spec.add_development_dependency 'appraisal'
|
35
|
+
spec.add_development_dependency 'deep-cover'
|
34
36
|
spec.add_development_dependency 'rake', '~> 12'
|
35
37
|
spec.add_development_dependency 'rspec', '~> 3'
|
36
|
-
spec.add_development_dependency '
|
38
|
+
spec.add_development_dependency 'rubocop'
|
39
|
+
spec.add_development_dependency 'simplecov'
|
40
|
+
spec.add_development_dependency 'simplecov-lcov', '~> 0.8.0'
|
37
41
|
end
|
data/lib/dynamoid_lockable.rb
CHANGED
@@ -20,12 +20,13 @@ module DynamoidLockable
|
|
20
20
|
locked_until = Time.now + self.class.lock_config(name)[:duration]
|
21
21
|
|
22
22
|
result = self.class
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
.lockable(name, locker_name: locker_name)
|
24
|
+
.upsert(
|
25
|
+
hash_key,
|
26
|
+
range_value,
|
27
|
+
"#{name}_locked_until": locked_until,
|
28
|
+
"#{name}_locked_by": locker_name,
|
29
|
+
)
|
29
30
|
|
30
31
|
raise CouldNotAcquireLock unless result
|
31
32
|
|
@@ -42,7 +43,7 @@ module DynamoidLockable
|
|
42
43
|
ensure_lockable_field(name)
|
43
44
|
|
44
45
|
result = self.class.unlockable(name)
|
45
|
-
|
46
|
+
.upsert(hash_key, range_value, "#{name}_locked_until": nil)
|
46
47
|
|
47
48
|
raise CouldNotUnlock unless result
|
48
49
|
|
@@ -68,9 +69,7 @@ module DynamoidLockable
|
|
68
69
|
|
69
70
|
result = lock(name)
|
70
71
|
|
71
|
-
if config[:relock_every]&.positive?
|
72
|
-
relock_thread = create_relock_thread(name)
|
73
|
-
end
|
72
|
+
relock_thread = create_relock_thread(name) if config[:relock_every]&.positive?
|
74
73
|
|
75
74
|
yield
|
76
75
|
ensure
|
@@ -102,7 +101,7 @@ module DynamoidLockable
|
|
102
101
|
|
103
102
|
def locks_with(base_field, lock_for: DEFAULT_LOCK_TIME, relock_every: lock_for / 3)
|
104
103
|
self.lockable_fields = lockable_fields.merge(
|
105
|
-
base_field.to_sym => { duration: lock_for, relock_every: relock_every }
|
104
|
+
base_field.to_sym => { duration: lock_for, relock_every: relock_every },
|
106
105
|
)
|
107
106
|
|
108
107
|
field "#{base_field}_locked_until".to_sym, :datetime
|
@@ -113,7 +112,7 @@ module DynamoidLockable
|
|
113
112
|
ensure_lockable_field(lock_name)
|
114
113
|
|
115
114
|
advanced_where do |r|
|
116
|
-
r
|
115
|
+
key_filter(r) & (
|
117
116
|
(r.send("#{lock_name}_locked_by") == locker_name) |
|
118
117
|
!r.send("#{lock_name}_locked_until").exists? |
|
119
118
|
(r.send("#{lock_name}_locked_until") < Time.now)
|
@@ -129,10 +128,18 @@ module DynamoidLockable
|
|
129
128
|
ensure_lockable_field(lock_name)
|
130
129
|
|
131
130
|
advanced_where do |r|
|
132
|
-
r
|
131
|
+
key_filter(r) &
|
133
132
|
(r.send("#{lock_name}_locked_by") == locker_name)
|
134
133
|
end
|
135
134
|
end
|
135
|
+
|
136
|
+
def key_filter(condition_builder)
|
137
|
+
if range_key
|
138
|
+
condition_builder.public_send(hash_key).exists? & condition_builder.public_send(range_key).exists?
|
139
|
+
else
|
140
|
+
condition_builder.public_send(hash_key).exists?
|
141
|
+
end
|
142
|
+
end
|
136
143
|
end
|
137
144
|
|
138
145
|
def self.included(other)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamoid_lockable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Malinconico
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynamoid_advanced_where
|
@@ -30,6 +30,20 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rexml
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
33
47
|
- !ruby/object:Gem::Dependency
|
34
48
|
name: appraisal
|
35
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,6 +58,20 @@ dependencies:
|
|
44
58
|
- - ">="
|
45
59
|
- !ruby/object:Gem::Version
|
46
60
|
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: deep-cover
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
47
75
|
- !ruby/object:Gem::Dependency
|
48
76
|
name: rake
|
49
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,7 +101,7 @@ dependencies:
|
|
73
101
|
- !ruby/object:Gem::Version
|
74
102
|
version: '3'
|
75
103
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
104
|
+
name: rubocop
|
77
105
|
requirement: !ruby/object:Gem::Requirement
|
78
106
|
requirements:
|
79
107
|
- - ">="
|
@@ -86,6 +114,34 @@ dependencies:
|
|
86
114
|
- - ">="
|
87
115
|
- !ruby/object:Gem::Version
|
88
116
|
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: simplecov
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: simplecov-lcov
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: 0.8.0
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 0.8.0
|
89
145
|
description: Uses atomic writes to DynamoDB to ensure you hold an exclusive lock on
|
90
146
|
your records
|
91
147
|
email:
|
@@ -94,9 +150,15 @@ executables: []
|
|
94
150
|
extensions: []
|
95
151
|
extra_rdoc_files: []
|
96
152
|
files:
|
97
|
-
- ".
|
153
|
+
- ".github/workflows/lint.yaml"
|
154
|
+
- ".github/workflows/test.yaml"
|
98
155
|
- ".gitignore"
|
156
|
+
- ".rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-3-1-yml"
|
157
|
+
- ".rubocop-https---raw-githubusercontent-com-GetTerminus-ruby-shared-configs-master--rubocop-yml"
|
158
|
+
- ".rubocop.yml"
|
159
|
+
- ".ruby-version"
|
99
160
|
- Appraisals
|
161
|
+
- CHANGELOG.md
|
100
162
|
- Gemfile
|
101
163
|
- Gemfile.lock
|
102
164
|
- README.md
|
@@ -121,14 +183,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
183
|
requirements:
|
122
184
|
- - ">="
|
123
185
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
186
|
+
version: 2.7.0
|
125
187
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
188
|
requirements:
|
127
189
|
- - ">="
|
128
190
|
- !ruby/object:Gem::Version
|
129
191
|
version: '0'
|
130
192
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
193
|
+
rubygems_version: 3.1.6
|
132
194
|
signing_key:
|
133
195
|
specification_version: 4
|
134
196
|
summary: Lock your Dynamoid records for only your use
|
data/.circleci/config.yml
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
version: 2.0
|
2
|
-
|
3
|
-
workflows:
|
4
|
-
version: 2
|
5
|
-
build:
|
6
|
-
jobs:
|
7
|
-
- "ruby-2.5"
|
8
|
-
- "ruby-2.6"
|
9
|
-
- "ruby-2.7"
|
10
|
-
|
11
|
-
jobs:
|
12
|
-
"ruby-2.5":
|
13
|
-
docker:
|
14
|
-
- image: ruby:2.5
|
15
|
-
- image: amazon/dynamodb-local
|
16
|
-
environment:
|
17
|
-
MAX_HEAP_SIZE: 1024m
|
18
|
-
HEAP_NEWSIZE: 512m
|
19
|
-
|
20
|
-
steps:
|
21
|
-
- checkout
|
22
|
-
- restore_cache:
|
23
|
-
keys:
|
24
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
25
|
-
# fallback to using the latest cache if no exact match is found
|
26
|
-
- v1-dependencies-
|
27
|
-
|
28
|
-
- run:
|
29
|
-
name: install dependencies
|
30
|
-
command: |
|
31
|
-
gem update bundler
|
32
|
-
bundle install
|
33
|
-
bundle exec appraisal install
|
34
|
-
- save_cache:
|
35
|
-
paths:
|
36
|
-
- ./vendor/bundle
|
37
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
38
|
-
- run: bundle exec appraisal rspec --format progress
|
39
|
-
|
40
|
-
"ruby-2.6":
|
41
|
-
docker:
|
42
|
-
- image: ruby:2.6
|
43
|
-
- image: amazon/dynamodb-local
|
44
|
-
environment:
|
45
|
-
MAX_HEAP_SIZE: 1024m
|
46
|
-
HEAP_NEWSIZE: 512m
|
47
|
-
|
48
|
-
steps:
|
49
|
-
- checkout
|
50
|
-
- restore_cache:
|
51
|
-
keys:
|
52
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
53
|
-
# fallback to using the latest cache if no exact match is found
|
54
|
-
- v1-dependencies-
|
55
|
-
|
56
|
-
- run:
|
57
|
-
name: install dependencies
|
58
|
-
command: |
|
59
|
-
gem update bundler
|
60
|
-
bundle install
|
61
|
-
bundle exec appraisal install
|
62
|
-
- save_cache:
|
63
|
-
paths:
|
64
|
-
- ./vendor/bundle
|
65
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
66
|
-
- run: bundle exec appraisal rspec --format progress
|
67
|
-
|
68
|
-
"ruby-2.7":
|
69
|
-
docker:
|
70
|
-
- image: ruby:2.7
|
71
|
-
- image: amazon/dynamodb-local
|
72
|
-
environment:
|
73
|
-
MAX_HEAP_SIZE: 1024m
|
74
|
-
HEAP_NEWSIZE: 512m
|
75
|
-
|
76
|
-
steps:
|
77
|
-
- checkout
|
78
|
-
- restore_cache:
|
79
|
-
keys:
|
80
|
-
- v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
81
|
-
# fallback to using the latest cache if no exact match is found
|
82
|
-
- v1-dependencies-
|
83
|
-
|
84
|
-
- run:
|
85
|
-
name: install dependencies
|
86
|
-
command: |
|
87
|
-
gem update bundler
|
88
|
-
bundle install
|
89
|
-
bundle exec appraisal install
|
90
|
-
- save_cache:
|
91
|
-
paths:
|
92
|
-
- ./vendor/bundle
|
93
|
-
key: v1-dependencies-{{ checksum "Gemfile.lock" }}-{{ checksum "Appraisals" }}
|
94
|
-
- run: bundle exec appraisal rspec --format progress
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|