services 0.2.7 → 0.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/services/modules/uniqueness_checker.rb +4 -4
- data/lib/services/version.rb +1 -1
- data/spec/services/base_spec.rb +11 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b3bc560efbbf48e28224e43a9b0c38a94c0e3e3
|
4
|
+
data.tar.gz: 139c86d2e85f88781eb1999fb80123a18c66e009
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 48140e2d271a70fba7de535c1ce8249937e25013c02640265f877e3f6d9f2e8c81ed4288abfd30ba3eeecdce0a76b5a0a1e2e2191825f54038fc62591281650c
|
7
|
+
data.tar.gz: 94d5b1d545f3d3b72e1e343579f84452219f03ba6528380fbf8b9d635eaf944774ea127cd8f23dd67a116fef55a5d3972728e4afe35c847992ae59ac446e7fd6
|
@@ -15,13 +15,13 @@ module Services
|
|
15
15
|
raise 'Could not find uniqueness args' unless defined?(@uniqueness_args)
|
16
16
|
args = @uniqueness_args
|
17
17
|
end
|
18
|
-
@uniqueness_keys ||= []
|
19
18
|
new_uniqueness_key = uniqueness_key(args)
|
20
|
-
raise "A uniqueness key with args #{args.inspect} already exists." if @uniqueness_keys.include?(new_uniqueness_key)
|
21
|
-
@uniqueness_keys << new_uniqueness_key
|
22
19
|
if similar_service_id = Services.configuration.redis.get(new_uniqueness_key)
|
23
20
|
raise self.class::NotUniqueError, "Service #{self.class} with uniqueness args #{args} is not unique, a similar service is already running: #{similar_service_id}"
|
24
21
|
else
|
22
|
+
@uniqueness_keys ||= []
|
23
|
+
raise "A uniqueness key with args #{args.inspect} already exists." if @uniqueness_keys.include?(new_uniqueness_key)
|
24
|
+
@uniqueness_keys << new_uniqueness_key
|
25
25
|
Services.configuration.redis.setex new_uniqueness_key, 60 * 60, @id
|
26
26
|
end
|
27
27
|
end
|
@@ -30,7 +30,7 @@ module Services
|
|
30
30
|
@uniqueness_args = args
|
31
31
|
super
|
32
32
|
ensure
|
33
|
-
Services.configuration.redis.del @uniqueness_keys
|
33
|
+
Services.configuration.redis.del @uniqueness_keys unless @uniqueness_keys.nil? || @uniqueness_keys.empty?
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
data/lib/services/version.rb
CHANGED
data/spec/services/base_spec.rb
CHANGED
@@ -119,17 +119,21 @@ describe Services::Base do
|
|
119
119
|
|
120
120
|
context 'checking for uniqueness' do
|
121
121
|
context 'when the service checks for uniqueness with the default args' do
|
122
|
-
it 'raises an error when the same job is executed
|
122
|
+
it 'raises an error when the same job is executed multiple times' do
|
123
123
|
wait_for_job_to_run UniqueService do
|
124
|
-
|
124
|
+
3.times do
|
125
|
+
expect { UniqueService.call }.to raise_error(UniqueService::NotUniqueError)
|
126
|
+
end
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
128
130
|
|
129
131
|
context 'when the service checks for uniqueness with custom args' do
|
130
|
-
it 'raises an error when a job with the same custom args is executed
|
132
|
+
it 'raises an error when a job with the same custom args is executed multiple times' do
|
131
133
|
wait_for_job_to_run UniqueWithCustomArgsService, 'foo', 'bar', 'baz' do
|
132
|
-
|
134
|
+
3.times do
|
135
|
+
expect { UniqueWithCustomArgsService.call('foo', 'bar', 'pelle') }.to raise_error(UniqueWithCustomArgsService::NotUniqueError)
|
136
|
+
end
|
133
137
|
expect { UniqueWithCustomArgsService.call('foo', 'baz', 'pelle') }.to_not raise_error
|
134
138
|
end
|
135
139
|
end
|
@@ -141,7 +145,9 @@ describe Services::Base do
|
|
141
145
|
it 'raises an error when one of the checks fails' do
|
142
146
|
wait_for_job_to_run UniqueMultipleService, *args do
|
143
147
|
args.each do |arg|
|
144
|
-
|
148
|
+
3.times do
|
149
|
+
expect { UniqueMultipleService.call(arg) }.to raise_error(UniqueMultipleService::NotUniqueError)
|
150
|
+
end
|
145
151
|
end
|
146
152
|
expect { UniqueMultipleService.call('pelle') }.to_not raise_error
|
147
153
|
end
|