sneakers 2.4.0 → 2.5.0

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: 681e186272e780e4a969428ad17b2cef7e2f2a17
4
- data.tar.gz: e26f11fd1c1282784a2b362d8e263f7b54cb9790
3
+ metadata.gz: 1e8f7e984a402f29c32f62b919a5ba0be9db25c1
4
+ data.tar.gz: 9502698889301eacdfa4fa94d9b7ae575e407ca7
5
5
  SHA512:
6
- metadata.gz: 33b0a1d5f160771d38b3a8613a8f5b6022709bd1188e73cf2258a130389769bbec744867c76663182b737177718116ed88742e9a61285e61b3b3e4c99ebe2187
7
- data.tar.gz: a6d4f4c557c7af9a01863b9b95ab3fd02bf4cb0a6670fe15dcd2e3c0f152839b0dba5a52b67271a83be1044f9b8e80a513f4f365343cc254ee5fb1ab22882719
6
+ metadata.gz: 842cabff8a0f3c2375533061b32a665d9e81102e53fee32eceb96f14d3126c78499a29e80efb0f247b10ed4de9fdb52f8aea57e7ccf65a7641ac020a28ab804c
7
+ data.tar.gz: 17e5b565b4162c7bbf4ddeffc8801309291c00684fe1c13914b0bae64bc81dce50772ce9874971cdabee462afe506a10b99f751636fc38d0ddc8e13080813ad9
@@ -12,6 +12,7 @@ module Sneakers
12
12
  end
13
13
 
14
14
  require 'sneakers/configuration'
15
+ require 'sneakers/errors'
15
16
  require 'sneakers/support/production_formatter'
16
17
  require 'sneakers/concerns/logging'
17
18
  require 'sneakers/concerns/metrics'
@@ -0,0 +1,5 @@
1
+ require 'timeout'
2
+
3
+ module Sneakers
4
+ class WorkerTimeout < Timeout::Error; end
5
+ end
@@ -46,6 +46,7 @@ module Sneakers
46
46
  retry_name = @opts[:retry_exchange] || "#{@worker_queue_name}-retry"
47
47
  error_name = @opts[:retry_error_exchange] || "#{@worker_queue_name}-error"
48
48
  requeue_name = @opts[:retry_requeue_exchange] || "#{@worker_queue_name}-retry-requeue"
49
+ retry_routing_key = @opts[:retry_routing_key] || "#"
49
50
 
50
51
  # Create the exchanges
51
52
  @retry_exchange, @error_exchange, @requeue_exchange = [retry_name, error_name, requeue_name].map do |name|
@@ -75,7 +76,7 @@ module Sneakers
75
76
  @error_queue.bind(@error_exchange, :routing_key => '#')
76
77
 
77
78
  # Finally, bind the worker queue to our requeue exchange
78
- queue.bind(@requeue_exchange, :routing_key => '#')
79
+ queue.bind(@requeue_exchange, :routing_key => retry_routing_key)
79
80
 
80
81
  @max_retries = @opts[:retry_max_times] || 5
81
82
 
@@ -137,7 +138,8 @@ module Sneakers
137
138
  error: reason,
138
139
  num_attempts: num_attempts,
139
140
  failed_at: Time.now.iso8601,
140
- payload: Base64.encode64(msg.to_s)
141
+ payload: Base64.encode64(msg.to_s),
142
+ properties: Base64.encode64(props.to_json)
141
143
  }.tap do |hash|
142
144
  if reason.is_a?(Exception)
143
145
  hash[:error_class] = reason.class.to_s
@@ -1,3 +1,3 @@
1
1
  module Sneakers
2
- VERSION = "2.4.0"
2
+ VERSION = "2.5.0"
3
3
  end
@@ -51,7 +51,7 @@ module Sneakers
51
51
 
52
52
  begin
53
53
  metrics.increment("work.#{self.class.name}.started")
54
- Timeout.timeout(@timeout_after, Timeout::Error) do
54
+ Timeout.timeout(@timeout_after, WorkerTimeout) do
55
55
  metrics.timing("work.#{self.class.name}.time") do
56
56
  if @call_with_params
57
57
  res = work_with_params(msg, delivery_info, metadata)
@@ -60,13 +60,15 @@ module Sneakers
60
60
  end
61
61
  end
62
62
  end
63
- rescue Timeout::Error => ex
63
+ rescue WorkerTimeout => ex
64
64
  res = :timeout
65
- worker_error(ex, log_msg: log_msg(msg), message: msg)
65
+ worker_error(ex, log_msg: log_msg(msg), class: self.class.name,
66
+ message: msg, delivery_info: delivery_info, metadata: metadata)
66
67
  rescue => ex
67
68
  res = :error
68
69
  error = ex
69
- worker_error(ex, log_msg: log_msg(msg), message: msg)
70
+ worker_error(ex, log_msg: log_msg(msg), class: self.class.name,
71
+ message: msg, delivery_info: delivery_info, metadata: metadata)
70
72
  end
71
73
 
72
74
  if @should_ack
@@ -131,8 +133,11 @@ module Sneakers
131
133
  @queue_opts = opts
132
134
  end
133
135
 
134
- def enqueue(msg)
135
- publisher.publish(msg, :to_queue => @queue_name)
136
+ def enqueue(msg, opts={})
137
+ opts[:routing_key] ||= @queue_opts[:routing_key]
138
+ opts[:to_queue] ||= @queue_name
139
+
140
+ publisher.publish(msg, opts)
136
141
  end
137
142
 
138
143
  private
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(/^(test|spec|features)\//)
19
19
  gem.require_paths = ['lib']
20
20
  gem.add_dependency 'serverengine', '~> 1.5.11'
21
- gem.add_dependency 'bunny', '~> 2.6'
21
+ gem.add_dependency 'bunny', '~> 2.6.4'
22
22
  gem.add_dependency 'thread', '~> 0.1.7'
23
23
  gem.add_dependency 'thor'
24
24
 
@@ -252,6 +252,7 @@ describe 'Handlers' do
252
252
  data['error'].must_equal('reject')
253
253
  data['num_attempts'].must_equal(2)
254
254
  data['payload'].must_equal(Base64.encode64(:reject.to_s))
255
+ data['properties'].must_equal(Base64.encode64(@props_with_x_death.to_json))
255
256
  Time.parse(data['failed_at']).wont_be_nil
256
257
  end
257
258
 
@@ -267,6 +268,7 @@ describe 'Handlers' do
267
268
  data['error'].must_equal('reject')
268
269
  data['num_attempts'].must_equal(4)
269
270
  data['payload'].must_equal(Base64.encode64(:reject.to_s))
271
+ data['properties'].must_equal(Base64.encode64(props_with_x_death_count.to_json))
270
272
  Time.parse(data['failed_at']).wont_be_nil
271
273
  end
272
274
 
@@ -316,6 +318,7 @@ describe 'Handlers' do
316
318
  data['error'].must_equal('timeout')
317
319
  data['num_attempts'].must_equal(2)
318
320
  data['payload'].must_equal(Base64.encode64(:timeout.to_s))
321
+ data['properties'].must_equal(Base64.encode64(@props_with_x_death.to_json))
319
322
  Time.parse(data['failed_at']).wont_be_nil
320
323
  end
321
324
  end
@@ -347,6 +350,7 @@ describe 'Handlers' do
347
350
  data['backtrace'].wont_be_nil
348
351
  data['num_attempts'].must_equal(2)
349
352
  data['payload'].must_equal(Base64.encode64('boom!'))
353
+ data['properties'].must_equal(Base64.encode64(@props_with_x_death.to_json))
350
354
  Time.parse(data['failed_at']).wont_be_nil
351
355
  end
352
356
  end
@@ -383,6 +387,7 @@ describe 'Handlers' do
383
387
  data['error'].must_equal('timeout')
384
388
  data['num_attempts'].must_equal(2)
385
389
  data['payload'].must_equal(Base64.encode64(payload.to_json))
390
+ data['properties'].must_equal(Base64.encode64(@props_with_x_death.to_json))
386
391
  end
387
392
 
388
393
  end
@@ -159,19 +159,16 @@ describe Sneakers::Worker do
159
159
 
160
160
  describe ".enqueue" do
161
161
  it "publishes a message to the class queue" do
162
- message = "my message"
163
- mock = MiniTest::Mock.new
162
+ message = 'test message'
164
163
 
165
- mock.expect(:publish, true) do |msg, opts|
166
- msg.must_equal(message)
167
- opts.must_equal(:to_queue => "defaults")
164
+ mock(Sneakers::Publisher).new(DummyWorker.queue_opts) do
165
+ mock(Object.new).publish(message, {
166
+ :routing_key => 'test.routing.key',
167
+ :to_queue => 'downloads'
168
+ })
168
169
  end
169
- end
170
170
 
171
- it "passes the configuration to the publisher" do
172
- opts = DummyWorker.queue_opts
173
- mock(Sneakers::Publisher).new(opts) { mock(Object.new).publish(anything, anything) }
174
- DummyWorker.enqueue(message)
171
+ DummyWorker.enqueue(message, :routing_key => 'test.routing.key')
175
172
  end
176
173
  end
177
174
 
@@ -361,7 +358,7 @@ describe Sneakers::Worker do
361
358
  header = Object.new
362
359
 
363
360
  mock(handler).timeout(header, nil, "msg")
364
- mock(w.logger).error(/error="execution expired" error_class=Timeout::Error backtrace=/)
361
+ mock(w.logger).error(/error="execution expired" error_class=Sneakers::WorkerTimeout backtrace=/)
365
362
 
366
363
  w.do_work(header, nil, "msg", handler)
367
364
  end
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: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dotan Nahum
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: serverengine
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.6'
33
+ version: 2.6.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2.6'
40
+ version: 2.6.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: thread
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -268,6 +268,7 @@ files:
268
268
  - lib/sneakers/concerns/metrics.rb
269
269
  - lib/sneakers/configuration.rb
270
270
  - lib/sneakers/error_reporter.rb
271
+ - lib/sneakers/errors.rb
271
272
  - lib/sneakers/handlers/maxretry.rb
272
273
  - lib/sneakers/handlers/oneshot.rb
273
274
  - lib/sneakers/metrics/logging_metrics.rb
@@ -321,7 +322,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
321
322
  version: '0'
322
323
  requirements: []
323
324
  rubyforge_project:
324
- rubygems_version: 2.5.1
325
+ rubygems_version: 2.4.5
325
326
  signing_key:
326
327
  specification_version: 4
327
328
  summary: Fast background processing framework for Ruby and RabbitMQ