shoryuken 2.0.1 → 2.0.2

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: b9bd900d75c3f095c8097f8e11bba2f062c12645
4
- data.tar.gz: 8ee013cdcd282b9feb0561c489cf6650f52d7724
3
+ metadata.gz: f62098d7fa2041d2ae1cfd8a4cfedd0e09766bbb
4
+ data.tar.gz: 38445deab5aeb3a08310d105264338d64e5d835d
5
5
  SHA512:
6
- metadata.gz: 9aa41d1fd13eaa44fad88398309b6e27c09b672ed8a0d37a1f2860610378ebe68088e31badf7764f7599d444418ad5695138ac073f77a78dd41eab47ac48a36c
7
- data.tar.gz: a84b8c0ce92cf30e794e8dfd5de5648f3446d256bb2a74f48718d74bc7bdea359140c704f83440b3837281d56da4cb40b664ae9d6e5347a4560a721015457995
6
+ metadata.gz: 7ac1f46247119f055a0ed55494d7e39f687520197790458effdb8b23323cf9cb8d54ba64ce5107e8e53285522c7083dc90298afc2b202589945b80c51d5c1835
7
+ data.tar.gz: 6c2997f79ad3822134fa0a2f5be6563e3b382ac17134a7afcdaf812c78719f56f657c430ee7b3b4880f0ca9022f3e17514f9e7e1a835a71283e65fa169e6d36d
@@ -1,3 +1,20 @@
1
+ ## [v2.0.2] - 2015-10-22
2
+
3
+ - Fix warnings that are triggered in some cases with the raise_error matcher
4
+ - [#144](https://github.com/phstc/shoryuken/pull/144)
5
+
6
+ - Add lifecycle event registration support
7
+ - [#141](https://github.com/phstc/shoryuken/pull/141)
8
+
9
+ - Allow passing array of messages to send_messages
10
+ - [#140](https://github.com/phstc/shoryuken/pull/140)
11
+
12
+ - Fix Active Job queue prefixing in Rails apps
13
+ - [#139](https://github.com/phstc/shoryuken/pull/139)
14
+
15
+ - Enable override the default queue with a :queue option
16
+ - [#147](https://github.com/phstc/shoryuken/pull/147)
17
+
1
18
  ## [v2.0.1] - 2015-10-09
2
19
 
3
20
  - Bump aws-sdk to ~> 2
@@ -13,4 +30,4 @@
13
30
 
14
31
  - README updates
15
32
  - [#122](https://github.com/phstc/shoryuken/pull/122)
16
- - [#120](https://github.com/phstc/shoryuken/pull/120)
33
+ - [#120](https://github.com/phstc/shoryuken/pull/120)
@@ -26,7 +26,12 @@ module Shoryuken
26
26
  queues: [],
27
27
  aws: {},
28
28
  delay: 0,
29
- timeout: 8
29
+ timeout: 8,
30
+ lifecycle_events: {
31
+ startup: [],
32
+ quiet: [],
33
+ shutdown: [],
34
+ }
30
35
  }
31
36
 
32
37
  @@queues = []
@@ -112,6 +117,20 @@ module Shoryuken
112
117
  @stop_callback = block
113
118
  end
114
119
 
120
+ # Register a block to run at a point in the Shoryuken lifecycle.
121
+ # :startup, :quiet or :shutdown are valid events.
122
+ #
123
+ # Shoryuken.configure_server do |config|
124
+ # config.on(:shutdown) do
125
+ # puts "Goodbye cruel world!"
126
+ # end
127
+ # end
128
+ def on(event, &block)
129
+ raise ArgumentError, "Symbols only please: #{event}" unless event.is_a?(Symbol)
130
+ raise ArgumentError, "Invalid event name: #{event}" unless options[:lifecycle_events].key?(event)
131
+ options[:lifecycle_events][event] << block
132
+ end
133
+
115
134
  attr_reader :aws_initialization_callback,
116
135
  :start_callback,
117
136
  :stop_callback
@@ -45,6 +45,8 @@ module Shoryuken
45
45
  callback.call
46
46
  end
47
47
 
48
+ fire_event(:startup)
49
+
48
50
  begin
49
51
  launcher.run
50
52
 
@@ -173,7 +175,7 @@ module Shoryuken
173
175
  logger.info { 'Received USR1, will soft shutdown down' }
174
176
 
175
177
  launcher.stop
176
-
178
+ fire_event(:quiet, true)
177
179
  exit 0
178
180
  when 'TTIN'
179
181
  Thread.list.each do |thread|
@@ -113,7 +113,7 @@ module Shoryuken
113
113
  end
114
114
 
115
115
  def prefix_active_job_queue_names
116
- return unless @options[:rails]
116
+ return unless defined? ::ActiveJob
117
117
  return unless Shoryuken.active_job_queue_name_prefixing
118
118
 
119
119
  queue_name_prefix = ::ActiveJob::Base.queue_name_prefix
@@ -37,6 +37,8 @@ module Shoryuken
37
37
  callback.call
38
38
  end
39
39
 
40
+ fire_event(:shutdown, true)
41
+
40
42
  @fetcher.terminate if @fetcher.alive?
41
43
 
42
44
  logger.info { "Shutting down #{@ready.size} quiet workers" }
@@ -42,7 +42,9 @@ module Shoryuken
42
42
  def sanitize_messages!(options)
43
43
  options = case
44
44
  when options.is_a?(Array)
45
- { entries: options.map.with_index { |m, index| { id: index.to_s, message_body: m } } }
45
+ { entries: options.map.with_index do |m, index|
46
+ { id: index.to_s }.merge(m.is_a?(Hash) ? m : { message_body: m })
47
+ end }
46
48
  when options.is_a?(Hash)
47
49
  options
48
50
  end
@@ -12,6 +12,20 @@ module Shoryuken
12
12
  Shoryuken.logger
13
13
  end
14
14
 
15
+ def fire_event(event, reverse = false)
16
+ logger.debug { "Firing '#{event}' lifecycle event" }
17
+ arr = Shoryuken.options[:lifecycle_events][event]
18
+ arr.reverse! if reverse
19
+ arr.each do |block|
20
+ begin
21
+ block.call
22
+ rescue => ex
23
+ logger.warn(event: event)
24
+ logger.warn "#{ex.class.name}: #{ex.message}"
25
+ end
26
+ end
27
+ end
28
+
15
29
  def elapsed(started_at)
16
30
  # elapsed in ms
17
31
  (Time.now - started_at) * 1000
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '2.0.1'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -6,7 +6,6 @@ module Shoryuken
6
6
 
7
7
  module ClassMethods
8
8
  def perform_async(body, options = {})
9
- options ||= {}
10
9
  options[:message_attributes] ||= {}
11
10
  options[:message_attributes]['shoryuken_class'] = {
12
11
  string_value: self.to_s,
@@ -15,7 +14,9 @@ module Shoryuken
15
14
 
16
15
  options[:message_body] = body
17
16
 
18
- Shoryuken::Client.queues(get_shoryuken_options['queue']).send_message(options)
17
+ queue = options.delete(:queue) || get_shoryuken_options['queue']
18
+
19
+ Shoryuken::Client.queues(queue).send_message(options)
19
20
  end
20
21
 
21
22
  def perform_in(interval, body, options = {})
@@ -55,8 +55,8 @@ describe Shoryuken::Middleware::Server::AutoDelete do
55
55
  expect(sqs_queue).to_not receive(:delete_messages)
56
56
 
57
57
  expect {
58
- subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise }
59
- }.to raise_error
58
+ subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'Error' }
59
+ }.to raise_error(RuntimeError, 'Error')
60
60
  end
61
61
  end
62
62
  end
@@ -25,7 +25,9 @@ describe Shoryuken::Middleware::Server::ExponentialBackoffRetry do
25
25
  it 'does not retry the job by default' do
26
26
  expect(sqs_msg).not_to receive(:change_visibility)
27
27
 
28
- expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.to raise_error
28
+ expect {
29
+ subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'Error' }
30
+ }.to raise_error(RuntimeError, 'Error')
29
31
  end
30
32
 
31
33
  it 'does not retry the job if :retry_intervals is empty' do
@@ -33,7 +35,9 @@ describe Shoryuken::Middleware::Server::ExponentialBackoffRetry do
33
35
 
34
36
  expect(sqs_msg).not_to receive(:change_visibility)
35
37
 
36
- expect { subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise } }.to raise_error
38
+ expect {
39
+ subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'Error' }
40
+ }.to raise_error(RuntimeError, 'Error')
37
41
  end
38
42
 
39
43
  it 'retries the job if :retry_intervals is non-empty' do
@@ -54,8 +54,8 @@ describe Shoryuken::Middleware::Server::Timing do
54
54
  end
55
55
 
56
56
  expect {
57
- subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise }
58
- }.to raise_error
57
+ subject.call(TestWorker.new, queue, sqs_msg, sqs_msg.body) { raise 'Error' }
58
+ }.to raise_error(RuntimeError, 'Error')
59
59
  end
60
60
  end
61
61
  end
@@ -299,7 +299,7 @@ describe Shoryuken::Processor do
299
299
  it 'does not extend the message invisibility' do
300
300
  expect(sqs_msg).to receive(:visibility_timeout=).never
301
301
  expect_any_instance_of(TestWorker).to receive(:perform).and_raise 'worker failed'
302
- expect { subject.process(queue, sqs_msg) }.to raise_error
302
+ expect { subject.process(queue, sqs_msg) }.to raise_error(RuntimeError, 'worker failed')
303
303
  end
304
304
  end
305
305
  end
@@ -77,6 +77,22 @@ describe Shoryuken::Queue do
77
77
  subject.send_messages(entries: [{ id: '0', message_body: 'msg1'}, { id: '1', message_body: 'msg2' }])
78
78
  end
79
79
 
80
+ it 'accepts an array of messages' do
81
+ expect(sqs).to receive(:send_message_batch).with(hash_including(entries: [{ id: '0', message_body: 'msg1', delay_seconds: 1, message_attributes: { attr: 'attr1' } }, { id: '1', message_body: 'msg2', delay_seconds: 1, message_attributes: { attr: 'attr2' } }]))
82
+
83
+ subject.send_messages([
84
+ {
85
+ message_body: 'msg1',
86
+ delay_seconds: 1,
87
+ message_attributes: { attr: 'attr1' }
88
+ }, {
89
+ message_body: 'msg2',
90
+ delay_seconds: 1,
91
+ message_attributes: { attr: 'attr2' }
92
+ }
93
+ ])
94
+ end
95
+
80
96
  it 'accepts an array of string' do
81
97
  expect(sqs).to receive(:send_message_batch).with(hash_including(entries: [{ id: '0', message_body: 'msg1'}, { id: '1', message_body: 'msg2' }]))
82
98
 
@@ -79,6 +79,23 @@ describe 'Shoryuken::Worker' do
79
79
 
80
80
  TestWorker.perform_async('delayed message', delay_seconds: 60)
81
81
  end
82
+
83
+ it 'accepts an `queue` option' do
84
+ new_queue = 'some_different_queue'
85
+
86
+ expect(Shoryuken::Client).to receive(:queues).with(new_queue).and_return(sqs_queue)
87
+
88
+ expect(sqs_queue).to receive(:send_message).with(
89
+ message_attributes: {
90
+ 'shoryuken_class' => {
91
+ string_value: TestWorker.to_s,
92
+ data_type: 'String'
93
+ }
94
+ },
95
+ message_body: 'delayed message')
96
+
97
+ TestWorker.perform_async('delayed message', queue: new_queue)
98
+ end
82
99
  end
83
100
 
84
101
  describe '.shoryuken_options' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shoryuken
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-09 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler