sneakers 1.0.2 → 1.0.3

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: 955c1e3e788a76c97ae9b89ee240a9a2d3f4aaf8
4
- data.tar.gz: 28a4049a67567ba36e434a471e280ba0f5fe20b2
3
+ metadata.gz: ec56c8e9d5a17b77884550db383bd199027c6df5
4
+ data.tar.gz: 057d82d280432901949988868f0643958cd26ec4
5
5
  SHA512:
6
- metadata.gz: 9405f6a0baf93ddf0211f7437138228e6bdeb76247d64675a8211775f540654bb89efe44497f5502d1582cf7855bae5d38c45986a167c3e39cd580ac2c98d24b
7
- data.tar.gz: 11b4a380a5b3a3e596f294d7406c8afed06a7d9e5679dd12907bc543e00580e05f18cb71331ef16c24e6b1881cadb8df90d29317e4ed8573b0d8de946c877ab3
6
+ metadata.gz: 9d57c46bf38eb2bbb9752cc4fdc14d2de9ff9abdd9cf5d32a5a9a89c68e62d1884ccff6ba9c46eae106ea02c30ed2b4f8faffe8d3e69a1527ba395b3c0a2663a
7
+ data.tar.gz: f31f033a8fb2173632e16f7bd2ac73d6e6572270e8c77cc6f3d8dd3510ae63cd02bd241d6609c488a5dbb93ecc34d1d66653985e1e7895265c185ef92f7fd10f
@@ -4,7 +4,7 @@ module Sneakers
4
4
  class Configuration
5
5
 
6
6
  extend Forwardable
7
- def_delegators :@hash, :to_hash, :[], :[]=, :merge!, :==, :fetch, :delete
7
+ def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete
8
8
 
9
9
  DEFAULTS = {
10
10
  # runner
@@ -39,6 +39,16 @@ module Sneakers
39
39
  @hash[:vhost] = AMQ::Settings.parse_amqp_url(@hash[:amqp]).fetch(:vhost, '/')
40
40
  end
41
41
 
42
+ def merge!(hash)
43
+ # parse vhost from amqp if vhost is not specified explicitly
44
+ if hash[:vhost].nil? && !hash[:amqp].nil?
45
+ hash = hash.dup
46
+ hash[:vhost] = AMQ::Settings.parse_amqp_url(hash[:amqp]).fetch(:vhost, '/')
47
+ end
48
+
49
+ @hash.merge!(hash)
50
+ end
51
+
42
52
  def merge(hash)
43
53
  instance = self.class.new
44
54
  instance.merge! to_hash
@@ -22,7 +22,8 @@ class Sneakers::Queue
22
22
  @channel = @bunny.create_channel
23
23
  @channel.prefetch(@opts[:prefetch])
24
24
 
25
- @exchange = @channel.exchange(@opts[:exchange],
25
+ exchange_name = @opts[:exchange]
26
+ @exchange = @channel.exchange(exchange_name,
26
27
  :type => @opts[:exchange_type],
27
28
  :durable => @opts[:durable])
28
29
 
@@ -35,8 +36,10 @@ class Sneakers::Queue
35
36
  queue_durable = @opts[:queue_durable].nil? ? @opts[:durable] : @opts[:queue_durable]
36
37
  queue = @channel.queue(@name, :durable => queue_durable, :arguments => @opts[:arguments])
37
38
 
38
- routing_keys.each do |key|
39
- queue.bind(@exchange, :routing_key => key)
39
+ if exchange_name.length > 0
40
+ routing_keys.each do |key|
41
+ queue.bind(@exchange, :routing_key => key)
42
+ end
40
43
  end
41
44
 
42
45
  # NOTE: we are using the worker's options. This is necessary so the handler
@@ -1,3 +1,3 @@
1
1
  module Sneakers
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -50,7 +50,7 @@ module Sneakers
50
50
 
51
51
  begin
52
52
  metrics.increment("work.#{self.class.name}.started")
53
- Timeout.timeout(@timeout_after) do
53
+ Timeout.timeout(@timeout_after, Timeout::Error) do
54
54
  metrics.timing("work.#{self.class.name}.time") do
55
55
  if @call_with_params
56
56
  res = work_with_params(msg, delivery_info, metadata)
data/sneakers.gemspec CHANGED
@@ -16,9 +16,9 @@ Gem::Specification.new do |gem|
16
16
  gem.executables = gem.files.grep(/^bin/).map { |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(/^(test|spec|features)\//)
18
18
  gem.require_paths = ['lib']
19
- gem.add_dependency 'serverengine'
19
+ gem.add_dependency 'serverengine', '~> 1.5.5'
20
20
  gem.add_dependency 'bunny', '~> 1.7.0'
21
- gem.add_dependency 'thread'
21
+ gem.add_dependency 'thread', '0.1.5'
22
22
  gem.add_dependency 'thor'
23
23
 
24
24
  gem.add_development_dependency 'rr'
@@ -30,5 +30,6 @@ Gem::Specification.new do |gem|
30
30
  gem.add_development_dependency 'simplecov-rcov-text'
31
31
  gem.add_development_dependency 'rake'
32
32
  gem.add_development_dependency 'minitest'
33
+ gem.add_development_dependency 'guard'
33
34
  end
34
35
 
@@ -32,6 +32,39 @@ describe Sneakers::Configuration do
32
32
  end
33
33
  end
34
34
 
35
+ it 'should parse vhost from amqp option' do
36
+ env_url = 'amqp://foo:bar@localhost:5672/foobarvhost'
37
+ with_env('RABBITMQ_URL', env_url) do
38
+ url = 'amqp://foo:bar@localhost:5672/testvhost'
39
+ config = Sneakers::Configuration.new
40
+ config.merge!({ :amqp => url })
41
+ config[:vhost].must_equal 'testvhost'
42
+ end
43
+ end
44
+
45
+ it 'should not parse vhost from amqp option if vhost is specified explicitly' do
46
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
47
+ config = Sneakers::Configuration.new
48
+ config.merge!({ :amqp => url, :vhost => 'test_host' })
49
+ config[:vhost].must_equal 'test_host'
50
+ end
51
+
52
+ it 'should use vhost option if it is specified' do
53
+ url = 'amqp://foo:bar@localhost:5672/foobarvhost'
54
+ with_env('RABBITMQ_URL', url) do
55
+ config = Sneakers::Configuration.new
56
+ config.merge!({ :vhost => 'test_host' })
57
+ config[:vhost].must_equal 'test_host'
58
+ end
59
+ end
60
+
61
+ it 'should use default vhost if vhost is not specified in amqp option' do
62
+ url = 'amqp://foo:bar@localhost:5672'
63
+ config = Sneakers::Configuration.new
64
+ config.merge!({ :amqp => url })
65
+ config[:vhost].must_equal '/'
66
+ end
67
+
35
68
  def with_env(key, value)
36
69
  old_value = ENV[key]
37
70
  ENV[key] = value
@@ -39,4 +72,4 @@ describe Sneakers::Configuration do
39
72
  ensure
40
73
  ENV[key] = old_value
41
74
  end
42
- end
75
+ end
@@ -8,35 +8,38 @@ describe Sneakers::Queue do
8
8
  Sneakers.configure
9
9
  end
10
10
 
11
- describe "#subscribe" do
12
- let :queue_vars do
13
- {
14
- :prefetch => 25,
15
- :durable => true,
16
- :ack => true,
17
- :heartbeat => 2,
18
- :vhost => '/',
19
- :exchange => "sneakers",
20
- :exchange_type => :direct
21
- }
22
- end
11
+ let :queue_vars do
12
+ {
13
+ :prefetch => 25,
14
+ :durable => true,
15
+ :ack => true,
16
+ :heartbeat => 2,
17
+ :vhost => '/',
18
+ :exchange => "sneakers",
19
+ :exchange_type => :direct
20
+ }
21
+ end
22
+
23
+ before do
24
+ @mkbunny = Object.new
25
+ @mkchan = Object.new
26
+ @mkex = Object.new
27
+ @mkqueue = Object.new
28
+ @mkqueue_nondurable = Object.new
29
+ @mkworker = Object.new
23
30
 
31
+ mock(@mkbunny).start {}
32
+ mock(@mkbunny).create_channel{ @mkchan }
33
+ mock(Bunny).new(anything, :vhost => '/', :heartbeat => 2){ @mkbunny }
34
+
35
+ mock(@mkchan).prefetch(25)
36
+
37
+ stub(@mkworker).opts { { :exchange => 'test-exchange' } }
38
+ end
39
+
40
+ describe "#subscribe with sneakers exchange" do
24
41
  before do
25
- @mkbunny = Object.new
26
- @mkchan = Object.new
27
- @mkex = Object.new
28
- @mkqueue = Object.new
29
- @mkqueue_nondurable = Object.new
30
- @mkworker = Object.new
31
-
32
- mock(@mkbunny).start {}
33
- mock(@mkbunny).create_channel{ @mkchan }
34
- mock(Bunny).new(anything, :vhost => '/', :heartbeat => 2){ @mkbunny }
35
-
36
- mock(@mkchan).prefetch(25)
37
42
  mock(@mkchan).exchange("sneakers", :type => :direct, :durable => true){ @mkex }
38
-
39
- stub(@mkworker).opts { { :exchange => 'test-exchange' } }
40
43
  end
41
44
 
42
45
  it "should setup a bunny queue according to configuration values" do
@@ -86,5 +89,29 @@ describe Sneakers::Queue do
86
89
  myqueue = q.instance_variable_get(:@queue)
87
90
  end
88
91
  end
92
+
93
+ describe "#subscribe with default exchange" do
94
+ before do
95
+ # expect default exchange
96
+ queue_vars[:exchange] = ""
97
+ mock(@mkchan).exchange("", :type => :direct, :durable => true){ @mkex }
98
+ end
99
+
100
+ it "does not bind to exchange" do
101
+ mock(@mkchan).queue("downloads", :durable => true) { @mkqueue }
102
+ @handler = Object.new
103
+ worker_opts = { :handler => @handler }
104
+ stub(@mkworker).opts { worker_opts }
105
+ mock(@handler).new(@mkchan, @mkqueue, worker_opts).once
106
+
107
+ stub(@mkqueue).bind do
108
+ raise "bind should not be called"
109
+ end
110
+
111
+ stub(@mkqueue).subscribe
112
+ q = Sneakers::Queue.new("downloads", queue_vars)
113
+ q.subscribe(@mkworker)
114
+ end
115
+ end
89
116
  end
90
117
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneakers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dotan Nahum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-13 00:00:00.000000000 Z
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.5.5
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: 1.5.5
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bunny
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: thread
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.1.5
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.1.5
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +192,20 @@ dependencies:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: guard
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
195
209
  description: " Fast background processing framework for Ruby and RabbitMQ "
196
210
  email:
197
211
  - jondotan@gmail.com