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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbbec960a41d81815da15861aa4e5abf3941cd46
4
- data.tar.gz: 4e390c06247de93c8eb6e45050392566767a2903
3
+ metadata.gz: 7b3bc560efbbf48e28224e43a9b0c38a94c0e3e3
4
+ data.tar.gz: 139c86d2e85f88781eb1999fb80123a18c66e009
5
5
  SHA512:
6
- metadata.gz: 998625c59ca525eb537f52d5317cff7d0ac8cb68f787bb1b46dbf16f33a00917eae854ee24e27763a13422e22b6b62a4e65bda26213e8a527f0d356a46e7adea
7
- data.tar.gz: 73db3259b704dc5b18a3468561c634cfc84d71ffea2288df47523dd9eda51379ae498a96aa470751f2daffc85d5ee2dc5948d312888d10278aa9dfb9138832ec
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 if defined?(@uniqueness_keys)
33
+ Services.configuration.redis.del @uniqueness_keys unless @uniqueness_keys.nil? || @uniqueness_keys.empty?
34
34
  end
35
35
 
36
36
  private
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '0.2.7'
2
+ VERSION = '0.2.8'
3
3
  end
@@ -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 twice' do
122
+ it 'raises an error when the same job is executed multiple times' do
123
123
  wait_for_job_to_run UniqueService do
124
- expect { UniqueService.call }.to raise_error(UniqueService::NotUniqueError)
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 twice' do
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
- expect { UniqueWithCustomArgsService.call('foo', 'bar', 'pelle') }.to raise_error(UniqueWithCustomArgsService::NotUniqueError)
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
- expect { UniqueMultipleService.call(arg) }.to raise_error(UniqueMultipleService::NotUniqueError)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: services
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
4
+ version: 0.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Meurer