simple_mutex 1.0.1 → 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/main.yml +9 -6
- data/.rubocop.yml +9 -0
- data/CHANGELOG.md +11 -1
- data/Gemfile.lock +98 -80
- data/lib/simple_mutex/base_cleaner.rb +32 -13
- data/lib/simple_mutex/helper.rb +19 -21
- data/lib/simple_mutex/mutex.rb +41 -14
- data/lib/simple_mutex/version.rb +1 -1
- data/simple_mutex.gemspec +13 -13
- metadata +72 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a4ce21298ffcca5c95af76310c29841548fff255770558e5c1444c63e5fdccf
|
4
|
+
data.tar.gz: fa7eec6953a65ab8f6db36b6d93f6744a8ff3ff5f2a34a622d2f731c2e9ed516
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1822c4930ee9f2d8f6b30af2f6a7c984e94744e58c0533731dd31cd14af5d144862e008d0b4e6bae5e62d8390ae416eb2196a21689ca470832ed4fb505de15c8
|
7
|
+
data.tar.gz: b275b789bab42e4b666aebcd9b234757de7d0ba90580b58d2a2d585f24eaefc0155bf70010be342f86aa50a287e4281e21a9f8df62d387da15b34dae637f4c7f
|
data/.github/workflows/main.yml
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
name: CI
|
2
2
|
|
3
|
-
on:
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- "*"
|
7
|
+
push:
|
8
|
+
branches:
|
9
|
+
- main
|
4
10
|
|
5
11
|
jobs:
|
6
12
|
test:
|
7
13
|
runs-on: ubuntu-latest
|
8
14
|
|
9
|
-
# We want to run on external PRs, but not on our own internal PRs as they'll be run on push event
|
10
|
-
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != 'umbrellio/table_sync'
|
11
|
-
|
12
15
|
strategy:
|
13
16
|
fail-fast: false
|
14
17
|
matrix:
|
15
|
-
ruby: ["2.
|
18
|
+
ruby: ["2.7", "3.0", "3.1", "3.2"]
|
16
19
|
|
17
20
|
name: ${{ matrix.ruby }}
|
18
21
|
|
@@ -24,7 +27,7 @@ jobs:
|
|
24
27
|
ruby-version: ${{ matrix.ruby }}
|
25
28
|
bundler-cache: true
|
26
29
|
|
27
|
-
- run: bundle exec
|
30
|
+
- run: bundle exec bundle-audit check --update
|
28
31
|
- run: bundle exec rubocop
|
29
32
|
- run: bundle exec rspec
|
30
33
|
|
data/.rubocop.yml
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
inherit_gem:
|
2
2
|
rubocop-config-umbrellio: lib/rubocop.yml
|
3
3
|
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.7
|
6
|
+
|
4
7
|
Layout/HashAlignment:
|
5
8
|
EnforcedHashRocketStyle:
|
6
9
|
- key
|
@@ -9,6 +12,12 @@ Layout/HashAlignment:
|
|
9
12
|
- key
|
10
13
|
- table
|
11
14
|
|
15
|
+
RSpec/IndexedLet:
|
16
|
+
Max: 3
|
17
|
+
|
12
18
|
Naming/VariableNumber:
|
13
19
|
Exclude:
|
14
20
|
- 'spec/**/*'
|
21
|
+
|
22
|
+
Performance/StringIdentifierArgument:
|
23
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,16 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [1.1.0]
|
6
|
+
- Updated Ruby version to 2.7, because version below is no longer officially used.
|
7
|
+
- Update 'redis' to the latest version to support redis-sentinel.
|
8
|
+
- Redis-namespace dependency moved to development dependency.
|
9
|
+
- Lock development dependency gem versions.
|
10
|
+
|
11
|
+
## [1.0.2]
|
12
|
+
- Redis-namespace dependency now requires version 1.8.2 or more recent, because thread safety was broken in 1.8.1
|
13
|
+
- Adds processing for case when `watch` fails in redis transactions (during unlocking).
|
14
|
+
|
5
15
|
## [1.0.1]
|
6
16
|
|
7
17
|
- Bugfix with active job/batches memoization in `SimpleMutex::SidekiqSupport::JobCleaner` and
|
@@ -11,4 +21,4 @@ All notable changes to this project will be documented in this file.
|
|
11
21
|
|
12
22
|
## [1.0.0]
|
13
23
|
|
14
|
-
Initial public release
|
24
|
+
Initial public release
|
data/Gemfile.lock
CHANGED
@@ -1,123 +1,141 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
simple_mutex (1.0
|
5
|
-
redis
|
6
|
-
redis-namespace
|
4
|
+
simple_mutex (1.1.0)
|
5
|
+
redis (>= 5.0)
|
7
6
|
sidekiq
|
8
7
|
|
9
8
|
GEM
|
10
9
|
remote: https://rubygems.org/
|
11
10
|
specs:
|
12
|
-
activesupport (
|
11
|
+
activesupport (7.1.0)
|
12
|
+
base64
|
13
|
+
bigdecimal
|
13
14
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
|
+
connection_pool (>= 2.2.5)
|
16
|
+
drb
|
14
17
|
i18n (>= 1.6, < 2)
|
15
18
|
minitest (>= 5.1)
|
19
|
+
mutex_m
|
16
20
|
tzinfo (~> 2.0)
|
17
|
-
zeitwerk (~> 2.3)
|
18
21
|
ast (2.4.2)
|
19
|
-
|
22
|
+
base64 (0.1.1)
|
23
|
+
bigdecimal (3.1.4)
|
24
|
+
bundler-audit (0.9.1)
|
20
25
|
bundler (>= 1.2.0, < 3)
|
21
26
|
thor (~> 1.0)
|
22
|
-
concurrent-ruby (1.
|
23
|
-
connection_pool (2.
|
24
|
-
diff-lcs (1.
|
27
|
+
concurrent-ruby (1.2.2)
|
28
|
+
connection_pool (2.4.1)
|
29
|
+
diff-lcs (1.5.0)
|
25
30
|
docile (1.4.0)
|
26
|
-
|
27
|
-
concurrent-ruby (~> 1.0)
|
28
|
-
minitest (5.14.4)
|
29
|
-
mock_redis (0.29.0)
|
31
|
+
drb (2.1.1)
|
30
32
|
ruby2_keywords
|
31
|
-
|
32
|
-
|
33
|
+
i18n (1.14.1)
|
34
|
+
concurrent-ruby (~> 1.0)
|
35
|
+
json (2.6.3)
|
36
|
+
minitest (5.20.0)
|
37
|
+
mock_redis (0.37.0)
|
38
|
+
mutex_m (0.1.2)
|
39
|
+
parallel (1.23.0)
|
40
|
+
parser (3.2.2.4)
|
33
41
|
ast (~> 2.4.1)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
42
|
+
racc
|
43
|
+
racc (1.7.1)
|
44
|
+
rack (3.0.8)
|
45
|
+
rainbow (3.1.1)
|
46
|
+
redis (5.0.7)
|
47
|
+
redis-client (>= 0.9.0)
|
48
|
+
redis-client (0.17.0)
|
49
|
+
connection_pool
|
50
|
+
redis-namespace (1.11.0)
|
51
|
+
redis (>= 4)
|
52
|
+
regexp_parser (2.8.1)
|
53
|
+
rexml (3.2.6)
|
54
|
+
rspec (3.12.0)
|
55
|
+
rspec-core (~> 3.12.0)
|
56
|
+
rspec-expectations (~> 3.12.0)
|
57
|
+
rspec-mocks (~> 3.12.0)
|
58
|
+
rspec-core (3.12.2)
|
59
|
+
rspec-support (~> 3.12.0)
|
60
|
+
rspec-expectations (3.12.3)
|
48
61
|
diff-lcs (>= 1.2.0, < 2.0)
|
49
|
-
rspec-support (~> 3.
|
50
|
-
rspec-mocks (3.
|
62
|
+
rspec-support (~> 3.12.0)
|
63
|
+
rspec-mocks (3.12.6)
|
51
64
|
diff-lcs (>= 1.2.0, < 2.0)
|
52
|
-
rspec-support (~> 3.
|
53
|
-
rspec-support (3.
|
54
|
-
rubocop (1.
|
65
|
+
rspec-support (~> 3.12.0)
|
66
|
+
rspec-support (3.12.1)
|
67
|
+
rubocop (1.50.2)
|
68
|
+
json (~> 2.3)
|
55
69
|
parallel (~> 1.10)
|
56
|
-
parser (>= 3.
|
70
|
+
parser (>= 3.2.0.0)
|
57
71
|
rainbow (>= 2.2.2, < 4.0)
|
58
72
|
regexp_parser (>= 1.8, < 3.0)
|
59
|
-
rexml
|
60
|
-
rubocop-ast (>= 1.
|
73
|
+
rexml (>= 3.2.5, < 4.0)
|
74
|
+
rubocop-ast (>= 1.28.0, < 2.0)
|
61
75
|
ruby-progressbar (~> 1.7)
|
62
|
-
unicode-display_width (>=
|
63
|
-
rubocop-ast (1.
|
64
|
-
parser (>= 3.
|
65
|
-
rubocop-
|
66
|
-
rubocop (
|
67
|
-
|
68
|
-
rubocop
|
69
|
-
rubocop-
|
70
|
-
rubocop-
|
71
|
-
rubocop-
|
72
|
-
|
73
|
-
rubocop (
|
76
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
77
|
+
rubocop-ast (1.29.0)
|
78
|
+
parser (>= 3.2.1.0)
|
79
|
+
rubocop-capybara (2.19.0)
|
80
|
+
rubocop (~> 1.41)
|
81
|
+
rubocop-config-umbrellio (1.50.0.85)
|
82
|
+
rubocop (~> 1.50.0)
|
83
|
+
rubocop-performance (~> 1.17.0)
|
84
|
+
rubocop-rails (~> 2.19.0)
|
85
|
+
rubocop-rake (~> 0.6.0)
|
86
|
+
rubocop-rspec (~> 2.20.0)
|
87
|
+
rubocop-sequel (~> 0.3.3)
|
88
|
+
rubocop-performance (1.17.1)
|
89
|
+
rubocop (>= 1.7.0, < 2.0)
|
74
90
|
rubocop-ast (>= 0.4.0)
|
75
|
-
rubocop-rails (2.
|
91
|
+
rubocop-rails (2.19.1)
|
76
92
|
activesupport (>= 4.2.0)
|
77
93
|
rack (>= 1.1)
|
78
|
-
rubocop (>=
|
79
|
-
rubocop-rake (0.
|
80
|
-
rubocop
|
81
|
-
rubocop-rspec (2.2.0)
|
94
|
+
rubocop (>= 1.33.0, < 2.0)
|
95
|
+
rubocop-rake (0.6.0)
|
82
96
|
rubocop (~> 1.0)
|
83
|
-
|
84
|
-
|
97
|
+
rubocop-rspec (2.20.0)
|
98
|
+
rubocop (~> 1.33)
|
99
|
+
rubocop-capybara (~> 2.17)
|
100
|
+
rubocop-sequel (0.3.4)
|
85
101
|
rubocop (~> 1.0)
|
86
|
-
ruby-progressbar (1.
|
102
|
+
ruby-progressbar (1.13.0)
|
87
103
|
ruby2_keywords (0.0.5)
|
88
|
-
sidekiq (
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
104
|
+
sidekiq (7.1.5)
|
105
|
+
concurrent-ruby (< 2)
|
106
|
+
connection_pool (>= 2.3.0)
|
107
|
+
rack (>= 2.2.4)
|
108
|
+
redis-client (>= 0.14.0)
|
109
|
+
simplecov (0.22.0)
|
93
110
|
docile (~> 1.1)
|
94
111
|
simplecov-html (~> 0.11)
|
95
112
|
simplecov_json_formatter (~> 0.1)
|
96
113
|
simplecov-html (0.12.3)
|
97
114
|
simplecov-lcov (0.8.0)
|
98
|
-
simplecov_json_formatter (0.1.
|
99
|
-
thor (1.
|
100
|
-
timecop (0.9.
|
101
|
-
tzinfo (2.0.
|
115
|
+
simplecov_json_formatter (0.1.4)
|
116
|
+
thor (1.2.2)
|
117
|
+
timecop (0.9.8)
|
118
|
+
tzinfo (2.0.6)
|
102
119
|
concurrent-ruby (~> 1.0)
|
103
|
-
unicode-display_width (2.
|
104
|
-
zeitwerk (2.5.1)
|
120
|
+
unicode-display_width (2.5.0)
|
105
121
|
|
106
122
|
PLATFORMS
|
107
|
-
|
123
|
+
x86_64-darwin-21
|
124
|
+
x86_64-linux
|
108
125
|
|
109
126
|
DEPENDENCIES
|
110
|
-
bundler
|
111
|
-
bundler-audit
|
112
|
-
mock_redis
|
113
|
-
|
114
|
-
|
115
|
-
rubocop
|
116
|
-
rubocop-
|
127
|
+
bundler (~> 2.4, >= 2.4.20)
|
128
|
+
bundler-audit (~> 0.9.1)
|
129
|
+
mock_redis (~> 0.37.0)
|
130
|
+
redis-namespace (~> 1.11)
|
131
|
+
rspec (~> 3.12)
|
132
|
+
rubocop (~> 1.50, >= 1.50)
|
133
|
+
rubocop-config-umbrellio (~> 1.50, >= 1.50.0.85)
|
134
|
+
rubocop-rspec (~> 2.20, >= 2.20)
|
117
135
|
simple_mutex!
|
118
|
-
simplecov
|
119
|
-
simplecov-lcov
|
120
|
-
timecop
|
136
|
+
simplecov (~> 0.22.0)
|
137
|
+
simplecov-lcov (~> 0.8.0)
|
138
|
+
timecop (~> 0.9.8)
|
121
139
|
|
122
140
|
BUNDLED WITH
|
123
|
-
2.
|
141
|
+
2.4.20
|
@@ -2,35 +2,54 @@
|
|
2
2
|
|
3
3
|
module SimpleMutex
|
4
4
|
class BaseCleaner
|
5
|
+
MAX_DEL_ATTEMPTS = 3
|
6
|
+
|
7
|
+
class SynchronizationAnomalyError < ::StandardError; end
|
8
|
+
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
5
10
|
def unlock
|
6
11
|
::SimpleMutex.redis_check!
|
7
12
|
|
8
13
|
logger&.info(start_msg)
|
9
14
|
|
10
15
|
redis.keys.select do |lock_key|
|
11
|
-
|
12
|
-
|
16
|
+
attempt = 0
|
17
|
+
|
18
|
+
begin
|
19
|
+
redis.watch(lock_key) do
|
20
|
+
raw_data = redis.get(lock_key)
|
21
|
+
raw_data = raw_data.value if raw_data.is_a?(Redis::Future)
|
22
|
+
|
23
|
+
next if raw_data.nil?
|
24
|
+
|
25
|
+
parsed_data = safe_parse(raw_data)
|
13
26
|
|
14
|
-
|
27
|
+
next unless parsed_data&.dig("payload", "type") == type
|
15
28
|
|
16
|
-
|
29
|
+
entity_id = parsed_data&.dig(*path_to_entity_id)
|
17
30
|
|
18
|
-
|
31
|
+
next if entity_id.nil? || active?(entity_id)
|
19
32
|
|
20
|
-
|
33
|
+
return_value = redis.multi { |multi| multi.del(lock_key) }
|
21
34
|
|
22
|
-
|
35
|
+
log_iteration(lock_key, raw_data, return_value) unless logger.nil?
|
23
36
|
|
24
|
-
|
37
|
+
result = return_value&.first
|
25
38
|
|
26
|
-
|
39
|
+
raise SynchronizationAnomalyError, "Sync anomaly." unless result.is_a?(Integer)
|
27
40
|
|
28
|
-
|
41
|
+
result.positive?
|
42
|
+
ensure
|
43
|
+
redis.unwatch
|
44
|
+
end
|
45
|
+
rescue SynchronizationAnomalyError
|
46
|
+
retry if (attempt += 1) < MAX_DEL_ATTEMPTS
|
29
47
|
end
|
30
48
|
end
|
31
49
|
|
32
50
|
logger&.info(end_msg)
|
33
51
|
end
|
52
|
+
# rubocop:enable Metrics/MethodLength
|
34
53
|
|
35
54
|
private
|
36
55
|
|
@@ -74,9 +93,9 @@ module SimpleMutex
|
|
74
93
|
end
|
75
94
|
|
76
95
|
def generate_log_msg(lock_key, raw_data, return_value)
|
77
|
-
"Trying to delete row with key <#{lock_key.inspect}> "\
|
78
|
-
|
79
|
-
|
96
|
+
"Trying to delete row with key <#{lock_key.inspect}> " \
|
97
|
+
"and value <#{raw_data.inspect}>. " \
|
98
|
+
"MULTI returned value <#{return_value.inspect}>."
|
80
99
|
end
|
81
100
|
|
82
101
|
def redis
|
data/lib/simple_mutex/helper.rb
CHANGED
@@ -29,39 +29,37 @@ module SimpleMutex
|
|
29
29
|
}
|
30
30
|
end
|
31
31
|
|
32
|
-
# rubocop:disable
|
32
|
+
# rubocop:disable Style/HashEachMethods
|
33
33
|
def list(mode: :default)
|
34
34
|
check_mode(mode)
|
35
35
|
|
36
36
|
result = []
|
37
|
+
job_types = %i[job default]
|
38
|
+
batch_types = %i[batch default]
|
37
39
|
|
38
40
|
redis.keys.each do |lock_key|
|
39
|
-
redis.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
if parsed_data.nil?
|
46
|
-
result << { key: lock_key, value: raw_data } if mode == :all
|
47
|
-
else
|
48
|
-
lock_type = parsed_data&.dig("payload", "type")
|
49
|
-
|
50
|
-
if (mode == :all) ||
|
51
|
-
(lock_type == "Job" && %i[job default].include?(mode)) ||
|
52
|
-
(lock_type == "Batch" && %i[batch default].include?(mode))
|
53
|
-
result << { key: lock_key, value: parsed_data }
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
41
|
+
raw_data = redis.get(lock_key)
|
42
|
+
|
43
|
+
next if raw_data.nil?
|
44
|
+
|
45
|
+
parsed_data = safe_parse(raw_data)
|
57
46
|
|
58
|
-
|
47
|
+
if parsed_data.nil?
|
48
|
+
result << { key: lock_key, value: raw_data } if mode == :all
|
49
|
+
else
|
50
|
+
lock_type = parsed_data&.dig("payload", "type")
|
51
|
+
|
52
|
+
if (mode == :all) ||
|
53
|
+
(lock_type == "Job" && job_types.include?(mode)) ||
|
54
|
+
(lock_type == "Batch" && batch_types.include?(mode))
|
55
|
+
result << { key: lock_key, value: parsed_data }
|
56
|
+
end
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
60
|
result
|
63
61
|
end
|
64
|
-
# rubocop:enable
|
62
|
+
# rubocop:enable Style/HashEachMethods
|
65
63
|
|
66
64
|
private
|
67
65
|
|
data/lib/simple_mutex/mutex.rb
CHANGED
@@ -6,8 +6,9 @@ require "json"
|
|
6
6
|
module SimpleMutex
|
7
7
|
class Mutex
|
8
8
|
DEFAULT_EXPIRES_IN = 60 * 60 # 1 hour
|
9
|
+
MAX_DEL_ATTEMPTS = 3
|
9
10
|
|
10
|
-
|
11
|
+
ERROR_MESSAGES = {
|
11
12
|
unlock: {
|
12
13
|
unknown: lambda do |lock_key|
|
13
14
|
"something when wrong when deleting lock key <#{lock_key}>."
|
@@ -18,6 +19,9 @@ module SimpleMutex
|
|
18
19
|
signature_mismatch: lambda do |lock_key|
|
19
20
|
"signature mismatch for lock key <#{lock_key}>."
|
20
21
|
end,
|
22
|
+
repeated_synchronization_anomaly: lambda do |lock_key|
|
23
|
+
"repeated synchronization anomaly for <#{lock_key}>."
|
24
|
+
end,
|
21
25
|
}.freeze,
|
22
26
|
lock: {
|
23
27
|
basic: lambda do |lock_key|
|
@@ -26,6 +30,8 @@ module SimpleMutex
|
|
26
30
|
}.freeze,
|
27
31
|
}.freeze
|
28
32
|
|
33
|
+
SynchronizationAnomalyError = Class.new(::StandardError)
|
34
|
+
|
29
35
|
BaseError = Class.new(::StandardError) do
|
30
36
|
attr_reader :lock_key
|
31
37
|
|
@@ -54,41 +60,62 @@ module SimpleMutex
|
|
54
60
|
|
55
61
|
redis = ::SimpleMutex.redis
|
56
62
|
|
57
|
-
|
58
|
-
|
63
|
+
attempt = 0
|
64
|
+
|
65
|
+
begin
|
66
|
+
redis.watch(lock_key) do
|
67
|
+
raw_data = redis.get(lock_key)
|
68
|
+
raw_data = raw_data.value if raw_data.is_a?(Redis::Future)
|
69
|
+
|
70
|
+
return false if raw_data.nil?
|
71
|
+
return false unless force || signature_valid?(raw_data, signature)
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
73
|
+
result = redis.multi { |multi| multi.del(lock_key) }.first
|
74
|
+
|
75
|
+
raise SynchronizationAnomalyError, "Sync anomaly." unless result.is_a?(Integer)
|
76
|
+
|
77
|
+
result.positive?
|
78
|
+
ensure
|
63
79
|
redis.unwatch
|
64
|
-
false
|
65
80
|
end
|
81
|
+
rescue SynchronizationAnomalyError
|
82
|
+
retry if (attempt += 1) < MAX_DEL_ATTEMPTS
|
83
|
+
raise_error(UnlockError, :repeated_synchronization_anomaly, lock_key)
|
66
84
|
end
|
67
85
|
end
|
68
86
|
|
87
|
+
# rubocop:disable Metrics/MethodLength
|
69
88
|
def unlock!(lock_key, signature: nil, force: false)
|
70
89
|
::SimpleMutex.redis_check!
|
71
90
|
|
72
91
|
redis = ::SimpleMutex.redis
|
73
92
|
|
74
|
-
|
75
|
-
|
93
|
+
attempt = 0
|
94
|
+
|
95
|
+
begin
|
96
|
+
redis.watch(lock_key) do
|
97
|
+
raw_data = redis.get(lock_key)
|
98
|
+
raw_data = raw_data.value if raw_data.is_a?(Redis::Future)
|
76
99
|
|
77
|
-
|
78
|
-
raise_error(UnlockError, :key_not_found, lock_key) unless raw_data
|
100
|
+
raise_error(UnlockError, :key_not_found, lock_key) if raw_data.nil?
|
79
101
|
|
80
102
|
unless force || signature_valid?(raw_data, signature)
|
81
103
|
raise_error(UnlockError, :signature_mismatch, lock_key)
|
82
104
|
end
|
83
105
|
|
84
|
-
|
106
|
+
result = redis.multi { |multi| multi.del(lock_key) }.first
|
85
107
|
|
86
|
-
|
108
|
+
raise SynchronizationAnomalyError, "Sync anomaly." unless result.is_a?(Integer)
|
109
|
+
raise_error(UnlockError, :unknown, lock_key) unless result.positive?
|
87
110
|
ensure
|
88
111
|
redis.unwatch
|
89
112
|
end
|
113
|
+
rescue SynchronizationAnomalyError
|
114
|
+
retry if (attempt += 1) < MAX_DEL_ATTEMPTS
|
115
|
+
raise_error(UnlockError, :repeated_synchronization_anomaly, lock_key)
|
90
116
|
end
|
91
117
|
end
|
118
|
+
# rubocop:enable Metrics/MethodLength
|
92
119
|
|
93
120
|
def with_lock(lock_key, **options, &block)
|
94
121
|
new(lock_key, **options).with_lock(&block)
|
@@ -96,7 +123,7 @@ module SimpleMutex
|
|
96
123
|
|
97
124
|
def raise_error(error_class, msg_template, lock_key)
|
98
125
|
template_base = error_class.name.split("::").last.gsub("Error", "").downcase.to_sym
|
99
|
-
error_msg =
|
126
|
+
error_msg = ERROR_MESSAGES[template_base][msg_template].call(lock_key)
|
100
127
|
|
101
128
|
raise(error_class.new(error_msg, lock_key))
|
102
129
|
end
|
data/lib/simple_mutex/version.rb
CHANGED
data/simple_mutex.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/umbrellio/simple_mutex"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
16
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
19
19
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -25,18 +25,18 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
26
|
spec.require_paths = ["lib"]
|
27
27
|
|
28
|
-
spec.add_runtime_dependency "redis"
|
29
|
-
spec.add_runtime_dependency "redis-namespace"
|
28
|
+
spec.add_runtime_dependency "redis", ">= 5.0"
|
30
29
|
spec.add_runtime_dependency "sidekiq"
|
31
30
|
|
32
|
-
spec.add_development_dependency "bundler"
|
33
|
-
spec.add_development_dependency "bundler-audit"
|
34
|
-
spec.add_development_dependency "mock_redis"
|
35
|
-
spec.add_development_dependency "
|
36
|
-
spec.add_development_dependency "
|
37
|
-
spec.add_development_dependency "rubocop
|
38
|
-
spec.add_development_dependency "rubocop-
|
39
|
-
spec.add_development_dependency "
|
40
|
-
spec.add_development_dependency "simplecov
|
41
|
-
spec.add_development_dependency "
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.4", ">= 2.4.20"
|
32
|
+
spec.add_development_dependency "bundler-audit", "~> 0.9.1"
|
33
|
+
spec.add_development_dependency "mock_redis", "~> 0.37.0"
|
34
|
+
spec.add_development_dependency "redis-namespace", "~> 1.11"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.12"
|
36
|
+
spec.add_development_dependency "rubocop", "~> 1.50", ">= 1.50"
|
37
|
+
spec.add_development_dependency "rubocop-config-umbrellio", "~> 1.50", ">= 1.50.0.85"
|
38
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.20", ">= 2.20"
|
39
|
+
spec.add_development_dependency "simplecov", "~> 0.22.0"
|
40
|
+
spec.add_development_dependency "simplecov-lcov", "~> 0.8.0"
|
41
|
+
spec.add_development_dependency "timecop", "~> 0.9.8"
|
42
42
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_mutex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bob-umbr
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|
@@ -16,16 +16,16 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '5.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '5.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: sidekiq
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,159 +39,183 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.4'
|
45
48
|
- - ">="
|
46
49
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
-
type: :
|
50
|
+
version: 2.4.20
|
51
|
+
type: :development
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
51
54
|
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '2.4'
|
52
58
|
- - ">="
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
60
|
+
version: 2.4.20
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
|
-
name: bundler
|
62
|
+
name: bundler-audit
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
58
64
|
requirements:
|
59
|
-
- - "
|
65
|
+
- - "~>"
|
60
66
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
67
|
+
version: 0.9.1
|
62
68
|
type: :development
|
63
69
|
prerelease: false
|
64
70
|
version_requirements: !ruby/object:Gem::Requirement
|
65
71
|
requirements:
|
66
|
-
- - "
|
72
|
+
- - "~>"
|
67
73
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
74
|
+
version: 0.9.1
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
76
|
+
name: mock_redis
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
72
78
|
requirements:
|
73
|
-
- - "
|
79
|
+
- - "~>"
|
74
80
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
81
|
+
version: 0.37.0
|
76
82
|
type: :development
|
77
83
|
prerelease: false
|
78
84
|
version_requirements: !ruby/object:Gem::Requirement
|
79
85
|
requirements:
|
80
|
-
- - "
|
86
|
+
- - "~>"
|
81
87
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
88
|
+
version: 0.37.0
|
83
89
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
90
|
+
name: redis-namespace
|
85
91
|
requirement: !ruby/object:Gem::Requirement
|
86
92
|
requirements:
|
87
|
-
- - "
|
93
|
+
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
95
|
+
version: '1.11'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
|
-
- - "
|
100
|
+
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
102
|
+
version: '1.11'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: rspec
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
|
-
- - "
|
107
|
+
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
109
|
+
version: '3.12'
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
|
-
- - "
|
114
|
+
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
116
|
+
version: '3.12'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: rubocop
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
114
120
|
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '1.50'
|
115
124
|
- - ">="
|
116
125
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
126
|
+
version: '1.50'
|
118
127
|
type: :development
|
119
128
|
prerelease: false
|
120
129
|
version_requirements: !ruby/object:Gem::Requirement
|
121
130
|
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.50'
|
122
134
|
- - ">="
|
123
135
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
136
|
+
version: '1.50'
|
125
137
|
- !ruby/object:Gem::Dependency
|
126
138
|
name: rubocop-config-umbrellio
|
127
139
|
requirement: !ruby/object:Gem::Requirement
|
128
140
|
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '1.50'
|
129
144
|
- - ">="
|
130
145
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
146
|
+
version: 1.50.0.85
|
132
147
|
type: :development
|
133
148
|
prerelease: false
|
134
149
|
version_requirements: !ruby/object:Gem::Requirement
|
135
150
|
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '1.50'
|
136
154
|
- - ">="
|
137
155
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
156
|
+
version: 1.50.0.85
|
139
157
|
- !ruby/object:Gem::Dependency
|
140
158
|
name: rubocop-rspec
|
141
159
|
requirement: !ruby/object:Gem::Requirement
|
142
160
|
requirements:
|
161
|
+
- - "~>"
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '2.20'
|
143
164
|
- - ">="
|
144
165
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
166
|
+
version: '2.20'
|
146
167
|
type: :development
|
147
168
|
prerelease: false
|
148
169
|
version_requirements: !ruby/object:Gem::Requirement
|
149
170
|
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '2.20'
|
150
174
|
- - ">="
|
151
175
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
176
|
+
version: '2.20'
|
153
177
|
- !ruby/object:Gem::Dependency
|
154
178
|
name: simplecov
|
155
179
|
requirement: !ruby/object:Gem::Requirement
|
156
180
|
requirements:
|
157
|
-
- - "
|
181
|
+
- - "~>"
|
158
182
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
183
|
+
version: 0.22.0
|
160
184
|
type: :development
|
161
185
|
prerelease: false
|
162
186
|
version_requirements: !ruby/object:Gem::Requirement
|
163
187
|
requirements:
|
164
|
-
- - "
|
188
|
+
- - "~>"
|
165
189
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
190
|
+
version: 0.22.0
|
167
191
|
- !ruby/object:Gem::Dependency
|
168
192
|
name: simplecov-lcov
|
169
193
|
requirement: !ruby/object:Gem::Requirement
|
170
194
|
requirements:
|
171
|
-
- - "
|
195
|
+
- - "~>"
|
172
196
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
197
|
+
version: 0.8.0
|
174
198
|
type: :development
|
175
199
|
prerelease: false
|
176
200
|
version_requirements: !ruby/object:Gem::Requirement
|
177
201
|
requirements:
|
178
|
-
- - "
|
202
|
+
- - "~>"
|
179
203
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
204
|
+
version: 0.8.0
|
181
205
|
- !ruby/object:Gem::Dependency
|
182
206
|
name: timecop
|
183
207
|
requirement: !ruby/object:Gem::Requirement
|
184
208
|
requirements:
|
185
|
-
- - "
|
209
|
+
- - "~>"
|
186
210
|
- !ruby/object:Gem::Version
|
187
|
-
version:
|
211
|
+
version: 0.9.8
|
188
212
|
type: :development
|
189
213
|
prerelease: false
|
190
214
|
version_requirements: !ruby/object:Gem::Requirement
|
191
215
|
requirements:
|
192
|
-
- - "
|
216
|
+
- - "~>"
|
193
217
|
- !ruby/object:Gem::Version
|
194
|
-
version:
|
218
|
+
version: 0.9.8
|
195
219
|
description: Redis-based mutex library for using with sidekiq jobs and batches.
|
196
220
|
email:
|
197
221
|
- bob@umbrellio.biz
|
@@ -235,14 +259,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
259
|
requirements:
|
236
260
|
- - ">="
|
237
261
|
- !ruby/object:Gem::Version
|
238
|
-
version: 2.
|
262
|
+
version: 2.7.0
|
239
263
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
264
|
requirements:
|
241
265
|
- - ">="
|
242
266
|
- !ruby/object:Gem::Version
|
243
267
|
version: '0'
|
244
268
|
requirements: []
|
245
|
-
rubygems_version: 3.
|
269
|
+
rubygems_version: 3.4.10
|
246
270
|
signing_key:
|
247
271
|
specification_version: 4
|
248
272
|
summary: Redis-based mutex library for using with sidekiq jobs and batches.
|