sneakers 1.0.3 → 1.0.4

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: ec56c8e9d5a17b77884550db383bd199027c6df5
4
- data.tar.gz: 057d82d280432901949988868f0643958cd26ec4
3
+ metadata.gz: 840d0c4111ae6ab4c2b97719597fa928632dd34b
4
+ data.tar.gz: f24a305085c2b43bee74922011ffd3daf5031d24
5
5
  SHA512:
6
- metadata.gz: 9d57c46bf38eb2bbb9752cc4fdc14d2de9ff9abdd9cf5d32a5a9a89c68e62d1884ccff6ba9c46eae106ea02c30ed2b4f8faffe8d3e69a1527ba395b3c0a2663a
7
- data.tar.gz: f31f033a8fb2173632e16f7bd2ac73d6e6572270e8c77cc6f3d8dd3510ae63cd02bd241d6609c488a5dbb93ecc34d1d66653985e1e7895265c185ef92f7fd10f
6
+ metadata.gz: 936db286d2c0638746771efa54c4bdc8cee4f78c641bdc38db42eaa8fad7bed13428223ac6988edcc10f9a5c883a28c054aeb7d4c842f4befcbc24654014c274
7
+ data.tar.gz: 426cf688b5e91c2e02bcb4c45fe420989592c6041419e0bf1cd8d4ae59b145426164ab669e17ac6e620481dc7734c798fcb53cb1d5c8e2ad1dc42c54f2881998
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2.0
4
- - 2.1.0
3
+ - 2.2
4
+ - 2.1
5
5
  - 2.0.0
6
6
  - 1.9.3
@@ -165,9 +165,16 @@ module Sneakers
165
165
  if headers.nil? || headers['x-death'].nil?
166
166
  0
167
167
  else
168
- headers['x-death'].select do |x_death|
168
+ x_death_array = headers['x-death'].select do |x_death|
169
169
  x_death['queue'] == @worker_queue_name
170
- end.count
170
+ end
171
+ if x_death_array.count > 0 && x_death_array.first['count']
172
+ # Newer versions of RabbitMQ return headers with a count key
173
+ x_death_array.inject(0) {|sum, x_death| sum + x_death['count']}
174
+ else
175
+ # Older versions return a separate x-death header for each failure
176
+ x_death_array.count
177
+ end
171
178
  end
172
179
  end
173
180
  private :failure_count
@@ -15,10 +15,10 @@ module Sneakers
15
15
  @exchange.publish(msg, options)
16
16
  end
17
17
 
18
- private
19
18
 
20
19
  attr_reader :exchange
21
20
 
21
+ private
22
22
  def ensure_connection!
23
23
  @bunny = Bunny.new(@opts[:amqp], heartbeat: @opts[:heartbeat], vhost: @opts[:vhost], :logger => Sneakers::logger)
24
24
  @bunny.start
@@ -46,7 +46,7 @@ class Sneakers::Queue
46
46
  # has the same configuration as the worker. Also pass along the exchange and
47
47
  # queue in case the handler requires access to them (for things like binding
48
48
  # retry queues, etc).
49
- handler_klass = worker.opts[:handler] || Sneakers::CONFIG[:handler]
49
+ handler_klass = worker.opts[:handler] || Sneakers::CONFIG.fetch(:handler)
50
50
  handler = handler_klass.new(@channel, queue, worker.opts)
51
51
 
52
52
  @consumer = queue.subscribe(:block => false, :manual_ack => @opts[:ack]) do | delivery_info, metadata, msg |
@@ -64,8 +64,15 @@ module Sneakers
64
64
  end
65
65
 
66
66
  private
67
- def make_serverengine_config
67
+ def make_serverengine_config
68
+ # From Sneakers#setup_general_logger, there's support for a Logger object
69
+ # in CONFIG[:log]. However, serverengine takes an object in :logger.
70
+ # Pass our logger object so there's no issue about sometimes passing a
71
+ # file and sometimes an object.
72
+ without_log = Sneakers::CONFIG.merge(@conf)
73
+ without_log.delete(:log)
68
74
  Sneakers::CONFIG.merge(@conf).merge({
75
+ :logger => Sneakers.logger,
69
76
  :worker_type => 'process',
70
77
  :worker_classes => @worker_classes
71
78
  })
@@ -1,3 +1,3 @@
1
1
  module Sneakers
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ['lib']
19
19
  gem.add_dependency 'serverengine', '~> 1.5.5'
20
20
  gem.add_dependency 'bunny', '~> 1.7.0'
21
- gem.add_dependency 'thread', '0.1.5'
21
+ gem.add_dependency 'thread', '~> 0.1.7'
22
22
  gem.add_dependency 'thor'
23
23
 
24
24
  gem.add_development_dependency 'rr'
@@ -4,10 +4,6 @@ require 'sneakers'
4
4
 
5
5
 
6
6
  describe Sneakers::Queue do
7
- before do
8
- Sneakers.configure
9
- end
10
-
11
7
  let :queue_vars do
12
8
  {
13
9
  :prefetch => 25,
@@ -21,6 +17,8 @@ describe Sneakers::Queue do
21
17
  end
22
18
 
23
19
  before do
20
+ Sneakers.configure
21
+
24
22
  @mkbunny = Object.new
25
23
  @mkchan = Object.new
26
24
  @mkex = Object.new
@@ -0,0 +1,26 @@
1
+ require 'logger'
2
+ require 'spec_helper'
3
+ require 'sneakers'
4
+
5
+ describe Sneakers::Runner do
6
+ let(:logger) { Logger.new('logtest.log') }
7
+
8
+ describe "with configuration that specifies a logger object" do
9
+ before do
10
+ Sneakers.configure(log: logger)
11
+ @runner = Sneakers::Runner.new([])
12
+ end
13
+
14
+ it 'passes the logger to serverengine' do
15
+ # Stub out ServerEngine::Daemon.run so we only exercise the way we invoke
16
+ # ServerEngine.create
17
+ any_instance_of(ServerEngine::Daemon) do |daemon|
18
+ stub(daemon).main{ return 0 }
19
+ end
20
+
21
+ @runner.run
22
+ # look at @runner's @se instance variable (actually of type Daemon)...and
23
+ # figure out what it's logger is...
24
+ end
25
+ end
26
+ end
@@ -103,6 +103,31 @@ describe 'Handlers' do
103
103
 
104
104
  describe 'Maxretry' do
105
105
  let(:max_retries) { nil }
106
+ let(:props_with_x_death_count) {
107
+ {
108
+ :headers => {
109
+ "x-death" => [
110
+ {
111
+ "count" => 3,
112
+ "reason" => "expired",
113
+ "queue" => "downloads-retry",
114
+ "time" => Time.now,
115
+ "exchange" => "RawMail-retry",
116
+ "routing-keys" => ["RawMail"]
117
+ },
118
+ {
119
+ "count" => 3,
120
+ "reason" => "rejected",
121
+ "queue" => "downloads",
122
+ "time" => Time.now,
123
+ "exchange" => "",
124
+ "routing-keys" => ["RawMail"]
125
+ }
126
+ ]
127
+ },
128
+ :delivery_mode => 1
129
+ }
130
+ }
106
131
 
107
132
  before(:each) do
108
133
  @opts = {
@@ -228,6 +253,21 @@ describe 'Handlers' do
228
253
  Time.parse(data['failed_at']).wont_be_nil
229
254
  end
230
255
 
256
+ it 'counts the number of attempts using the count key' do
257
+ mock(@header).routing_key { '#' }
258
+ mock(channel).acknowledge(37, false)
259
+
260
+ @error_exchange.extend MockPublish
261
+ worker.do_work(@header, props_with_x_death_count, :reject, @handler)
262
+ @error_exchange.called.must_equal(true)
263
+ @error_exchange.opts.must_equal({ :routing_key => '#' })
264
+ data = JSON.parse(@error_exchange.data)
265
+ data['error'].must_equal('reject')
266
+ data['num_attempts'].must_equal(4)
267
+ data['payload'].must_equal(Base64.encode64(:reject.to_s))
268
+ Time.parse(data['failed_at']).wont_be_nil
269
+ end
270
+
231
271
  end
232
272
  end
233
273
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sneakers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
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-04-08 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine
@@ -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.1.5
47
+ version: 0.1.7
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.1.5
54
+ version: 0.1.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: thor
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -261,6 +261,7 @@ files:
261
261
  - spec/sneakers/configuration_spec.rb
262
262
  - spec/sneakers/publisher_spec.rb
263
263
  - spec/sneakers/queue_spec.rb
264
+ - spec/sneakers/runner_spec.rb
264
265
  - spec/sneakers/sneakers_spec.rb
265
266
  - spec/sneakers/support/utils_spec.rb
266
267
  - spec/sneakers/worker_handlers_spec.rb
@@ -297,6 +298,7 @@ test_files:
297
298
  - spec/sneakers/configuration_spec.rb
298
299
  - spec/sneakers/publisher_spec.rb
299
300
  - spec/sneakers/queue_spec.rb
301
+ - spec/sneakers/runner_spec.rb
300
302
  - spec/sneakers/sneakers_spec.rb
301
303
  - spec/sneakers/support/utils_spec.rb
302
304
  - spec/sneakers/worker_handlers_spec.rb