services 0.2.10 → 0.2.11

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: 4d7c52da2120ba9940e89e59ba51357dc635bd6e
4
- data.tar.gz: 1648ad214dec51e86f96c171d6923f5645a8de61
3
+ metadata.gz: 2549878c0cdbb49f9e5ed0b5b8b795ec5c4a1bf6
4
+ data.tar.gz: c32abadba2f5a9d27e6940d4a4f1a2aebdbc7b99
5
5
  SHA512:
6
- metadata.gz: edd8efa7089b8d5b9b0f2d825ec613079b1dd96729fc0630deed1e6a158f1d4a60aeea39112f6a596deac973ea87d280a2173e1810b1b1d512c88c84714e79f6
7
- data.tar.gz: d3e2d308aff905357e9bf597f049b569a562a57eb00636a11a2e2baaa626190babd580936ef99b53152406599ab68026f97268f5242d9edb631db6fad9253752
6
+ metadata.gz: c8c21c50735329243d5f52fcfd450eef1c001d051e419a93bd961f11c3f81b1323f0a0024bf3ca93f37c030cee34c6c0e55961eb39074d8b626ef9714334f04b
7
+ data.tar.gz: e7d70bf7fcf64d3824bf682a8d0a4dfa89d3d6f8f5e6200fc539d1572f48fd47f43f6a8145122d9c568fcc268d7fee2472ee649a9331b7b9ea326046e9ae4efc
data/lib/services/base.rb CHANGED
@@ -29,7 +29,7 @@ module Services
29
29
  ids_or_objects = Array(ids_or_objects)
30
30
  ids, objects = ids_or_objects.grep(Fixnum), ids_or_objects.grep(klass)
31
31
  if ids.size + objects.size < ids_or_objects.size
32
- raise "All params must be either #{klass.to_s.pluralize} or Fixnums: #{ids_or_objects.map(&:class)}"
32
+ raise "All params must be either #{klass.to_s.pluralize} or Fixnums: #{ids_or_objects.map { |id_or_object| [id_or_object.class, id_or_object.inspect].join(' - ')}}"
33
33
  end
34
34
  if ids.any?
35
35
  find_service = "Services::#{klass.to_s.pluralize}::Find"
@@ -1,3 +1,3 @@
1
1
  module Services
2
- VERSION = '0.2.10'
2
+ VERSION = '0.2.11'
3
3
  end
@@ -59,8 +59,8 @@ describe Services::Base do
59
59
  end
60
60
 
61
61
  context 'when executed asynchronously' do
62
- fit 'finds its own worker' do
63
- 2.times { OwnWorkerService.perform_async }
62
+ it 'finds its own worker' do
63
+ 3.times { OwnWorkerService.perform_async }
64
64
  jid = OwnWorkerService.perform_async
65
65
  own_worker_data = wait_for { Services.configuration.redis.get(jid) }
66
66
  own_worker_json = JSON.parse(own_worker_data)
@@ -68,9 +68,9 @@ describe Services::Base::UniquenessChecker do
68
68
  context 'when the service checks for uniqueness with custom args' do
69
69
  it_behaves_like 'checking the uniqueness properly' do
70
70
  let(:service) { UniqueWithCustomArgsService }
71
- let(:args) { %w(foo bar baz) }
72
- let(:fail_args) { [%w(foo bar pelle)] }
73
- let(:pass_args) { [%w(foo baz pelle)] }
71
+ let(:args) { ['foo', 1, 'bar'] }
72
+ let(:fail_args) { [['foo', 1, 'pelle']] }
73
+ let(:pass_args) { [['foo', 2, 'bar']] }
74
74
  let(:keys_after_start) { 1 }
75
75
  end
76
76
  end
@@ -78,7 +78,7 @@ describe Services::Base::UniquenessChecker do
78
78
  context 'when the service checks for uniqueness multiple times' do
79
79
  it_behaves_like 'checking the uniqueness properly' do
80
80
  let(:service) { UniqueMultipleService }
81
- let(:args) { %w(foo bar baz) }
81
+ let(:args) { ['foo', 1, true] }
82
82
  let(:fail_args) { args.map { |arg| [arg] } }
83
83
  let(:pass_args) { [%w(pelle)] }
84
84
  let(:keys_after_start) { 3 }
data/spec/spec_helper.rb CHANGED
@@ -69,6 +69,12 @@ RSpec.configure do |config|
69
69
 
70
70
  # Copy call proxy
71
71
  FileUtils.cp CALL_PROXY_SOURCE, CALL_PROXY_DESTINATION
72
+
73
+ # Wait until Redis and Sidekiq are started
74
+ while !File.exist?(sidekiq_pidfile) || !File.exist?(redis_pidfile)
75
+ puts 'Waiting for Sidekiq and Redis to start...'
76
+ sleep 0.5
77
+ end
72
78
  end
73
79
 
74
80
  config.after :suite do
@@ -79,7 +85,7 @@ RSpec.configure do |config|
79
85
  system "bundle exec sidekiqctl stop #{sidekiq_pidfile} #{sidekiq_timeout}"
80
86
  while File.exist?(sidekiq_pidfile)
81
87
  puts 'Waiting for Sidekiq to shut down...'
82
- sleep 1
88
+ sleep 0.5
83
89
  end
84
90
 
85
91
  unless ENV['TRAVIS']
@@ -88,7 +94,7 @@ RSpec.configure do |config|
88
94
  system "#{redis_cli} -p #{redis_port} shutdown"
89
95
  while File.exist?(redis_pidfile)
90
96
  puts 'Waiting for Redis to shut down...'
91
- sleep 1
97
+ sleep 0.5
92
98
  end
93
99
  end
94
100
 
@@ -98,6 +104,10 @@ RSpec.configure do |config|
98
104
  File.truncate file, max_len if File.size(file) > max_len
99
105
  end
100
106
  end
107
+
108
+ config.after :each do
109
+ wait_for_all_jobs_to_finish
110
+ end
101
111
  end
102
112
 
103
113
  def options_hash_to_string(options)
@@ -3,7 +3,7 @@ require 'sidekiq/api'
3
3
  ExpectedDataNotFoundError = Class.new(StandardError)
4
4
 
5
5
  def wait_for(&block)
6
- 20.tries on: ExpectedDataNotFoundError, delay: 0.2 do
6
+ 50.tries on: ExpectedDataNotFoundError, delay: 0.1 do
7
7
  block.call or raise ExpectedDataNotFoundError
8
8
  end
9
9
  end
@@ -14,6 +14,12 @@ def worker_with_jid(jid)
14
14
  end
15
15
  end
16
16
 
17
+ def wait_for_all_jobs_to_finish
18
+ wait_for do
19
+ Sidekiq::Workers.new.size == 0
20
+ end
21
+ end
22
+
17
23
  def wait_for_job_to_run(job_class, *args, &block)
18
24
  job_class.perform_async(*args).tap do |jid|
19
25
  wait_for { worker_with_jid(jid) }
@@ -1,7 +1,3 @@
1
- # How long should the services sleep to ensure
2
- # that other services can be run in the meantime?
3
- SERVICE_SLEEP = 1 # seconds
4
-
5
1
  class Model
6
2
  attr_reader :id
7
3
 
@@ -71,14 +67,14 @@ end
71
67
  class UniqueService < Services::Base
72
68
  def call(on_error, sleep)
73
69
  check_uniqueness! on_error: on_error
74
- sleep SERVICE_SLEEP if sleep
70
+ sleep 0.5 if sleep
75
71
  end
76
72
  end
77
73
 
78
74
  class UniqueWithCustomArgsService < Services::Base
79
75
  def call(uniqueness_arg1, uniqueness_arg2, ignore_arg, on_error, sleep)
80
76
  check_uniqueness! uniqueness_arg1, uniqueness_arg2, on_error: on_error
81
- sleep SERVICE_SLEEP if sleep
77
+ sleep 0.5 if sleep
82
78
  end
83
79
  end
84
80
 
@@ -87,13 +83,13 @@ class UniqueMultipleService < Services::Base
87
83
  args.each do |arg|
88
84
  check_uniqueness! arg, on_error: on_error
89
85
  end
90
- sleep SERVICE_SLEEP if sleep
86
+ sleep 0.5 if sleep
91
87
  end
92
88
  end
93
89
 
94
90
  class NonUniqueService < Services::Base
95
91
  def call(on_error, sleep)
96
- sleep SERVICE_SLEEP if sleep
92
+ sleep 0.5 if sleep
97
93
  end
98
94
  end
99
95
 
@@ -104,7 +100,7 @@ class OwnWorkerService < Services::Base
104
100
  else
105
101
  Services.configuration.redis.set self.jid, own_worker.to_json
106
102
  end
107
- sleep SERVICE_SLEEP
103
+ sleep 0.5
108
104
  end
109
105
  end
110
106
 
@@ -115,7 +111,7 @@ class SiblingWorkersService < Services::Base
115
111
  else
116
112
  Services.configuration.redis.set self.jid, sibling_workers.to_json
117
113
  end
118
- sleep SERVICE_SLEEP
114
+ sleep 0.5
119
115
  end
120
116
  end
121
117
 
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.2.10
4
+ version: 0.2.11
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-08-29 00:00:00.000000000 Z
11
+ date: 2014-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake