services 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/services/base/uniqueness_checker.rb +22 -10
- data/lib/services/version.rb +1 -1
- data/services.gemspec +1 -1
- data/spec/services/base_spec.rb +18 -6
- data/spec/spec_helper.rb +2 -2
- data/spec/support/test_services.rb +10 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: df1ba6063f4bba38b277be74e5ec56cc71872078
|
4
|
+
data.tar.gz: 63d57f90d5d3372c9c88e0aedc79b25a39f3c185
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2ba9c8855a2c23bf6b559eb6023a8f72b0026e873e6307b7a3532ede57e9553bf3c8451dee1825f793ec183580a060bb4ff123604860dc6f1cd9d7b8a9f9636
|
7
|
+
data.tar.gz: 296aed48e3ce98785a24830bb944ab8763a0987cf38e31c91510372ebec2fbcd3dccd920bc23750e362976e9d146904db9e32e92e0acd62478df3dbcc205062e
|
@@ -2,21 +2,33 @@ module Services
|
|
2
2
|
class Base
|
3
3
|
module UniquenessChecker
|
4
4
|
def self.prepended(mod)
|
5
|
+
mod.instance_eval do
|
6
|
+
def check_uniqueness?
|
7
|
+
@check_uniqueness
|
8
|
+
end
|
9
|
+
|
10
|
+
def check_uniqueness!
|
11
|
+
@check_uniqueness = true
|
12
|
+
end
|
13
|
+
end
|
5
14
|
mod.const_set :NotUniqueError, Class.new(mod::Error)
|
6
15
|
end
|
7
16
|
|
8
17
|
def call(*args)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
18
|
+
if self.class.check_uniqueness?
|
19
|
+
key = unique_key(args)
|
20
|
+
if Services.configuration.redis.exists(key)
|
21
|
+
raise self.class::NotUniqueError
|
22
|
+
else
|
23
|
+
Services.configuration.redis.setex key, 60 * 60, Time.now
|
24
|
+
begin
|
25
|
+
super
|
26
|
+
ensure
|
27
|
+
Services.configuration.redis.del key
|
28
|
+
end
|
19
29
|
end
|
30
|
+
else
|
31
|
+
super
|
20
32
|
end
|
21
33
|
end
|
22
34
|
|
data/lib/services/version.rb
CHANGED
data/services.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
|
|
23
23
|
|
24
24
|
gem.add_development_dependency 'rake'
|
25
25
|
gem.add_development_dependency 'guard-rspec', '~> 4.2'
|
26
|
-
gem.add_development_dependency 'rspec', '>= 3.0.0.
|
26
|
+
gem.add_development_dependency 'rspec', '>= 3.0.0.rc1', '< 4'
|
27
27
|
gem.add_development_dependency 'sidekiq', '~> 3.0'
|
28
28
|
gem.add_development_dependency 'redis', '~> 3.0'
|
29
29
|
gem.add_runtime_dependency 'rails', '>= 3.0.0'
|
data/spec/services/base_spec.rb
CHANGED
@@ -64,12 +64,24 @@ describe Services::Base do
|
|
64
64
|
end
|
65
65
|
|
66
66
|
context 'checking for uniqueness' do
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
67
|
+
context 'when the service was set to check for uniqueness' do
|
68
|
+
it 'raises an error when the same job is executed twice' do
|
69
|
+
UniqueService.perform_async
|
70
|
+
sleep 0.5 # Wait for Sidekiq to start processing the job
|
71
|
+
expect do
|
72
|
+
UniqueService.call
|
73
|
+
end.to raise_error(UniqueService::NotUniqueError)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when the service was not set to check for uniqueness' do
|
78
|
+
it 'does not raise an error when the same job is executed twice' do
|
79
|
+
NonUniqueService.perform_async
|
80
|
+
sleep 0.5 # Wait for Sidekiq to start processing the job
|
81
|
+
expect do
|
82
|
+
NonUniqueService.call
|
83
|
+
end.to_not raise_error
|
84
|
+
end
|
73
85
|
end
|
74
86
|
end
|
75
87
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -32,7 +32,7 @@ RSpec.configure do |config|
|
|
32
32
|
config.filter_run :focus
|
33
33
|
config.order = 'random'
|
34
34
|
|
35
|
-
config.before :
|
35
|
+
config.before :suite do
|
36
36
|
# Start Redis
|
37
37
|
redis_options = {
|
38
38
|
daemonize: 'yes',
|
@@ -59,7 +59,7 @@ RSpec.configure do |config|
|
|
59
59
|
system "bundle exec sidekiq #{options_hash_to_string(sidekiq_options)}"
|
60
60
|
end
|
61
61
|
|
62
|
-
config.after :
|
62
|
+
config.after :suite do
|
63
63
|
# Stop Sidekiq
|
64
64
|
system "bundle exec sidekiqctl stop #{sidekiq_pidfile} #{sidekiq_timeout}"
|
65
65
|
while File.exist?(sidekiq_pidfile)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0.0.
|
47
|
+
version: 3.0.0.rc1
|
48
48
|
- - <
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '4'
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
requirements:
|
55
55
|
- - '>='
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: 3.0.0.
|
57
|
+
version: 3.0.0.rc1
|
58
58
|
- - <
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '4'
|