shoryuken 2.0.3 → 2.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: fff521cc6ef6173b686df9b83b5145901d3b20cb
4
- data.tar.gz: a7841963b11b2e4025ab368698e7571df0e506e9
3
+ metadata.gz: 25d7b8d6df3ab9ede1f0d7a6aba01d18e2a102f2
4
+ data.tar.gz: bf26e631ee57665f7b18d0a314259b48e71951cd
5
5
  SHA512:
6
- metadata.gz: 3c45ecb9a4a2d63408978af8eda9d7a2fcf85122a1a603b16550143dff23f16f6e145b0f2985f85b41f1be8f107b1c8a4bf232d75e931d9e0b5635fd82bba7ab
7
- data.tar.gz: 80410090f98a1a9d3112401c0fbf02e44b5b1f7fdb6e753df2f6ae2b4887927dcadc9937b2395fd5421c790892984c2e0fea4b3475077bf2411a0de0ecb854a9
6
+ metadata.gz: edfb890c3b31a38252bfecfd5f0f1c4d98b31c892f12106136fd91c973434f544e76c1ca48c860f2cd4f1065342231ca1dbd3a3f8752eb49613be45b57ce4c87
7
+ data.tar.gz: 3c36a03cb7bc41ce4038c5942b87f3e5b087d08a4e26e9387f9dc3222bbd4e50840af7ddd68f3b073712de5d8a629d57d29ec9387e855c16499183983fea0e04
data/.travis.yml CHANGED
@@ -15,3 +15,5 @@ notifications:
15
15
  on_failure: always
16
16
 
17
17
  script: SPEC_ALL=true bundle exec rspec spec
18
+ before_install:
19
+ - gem update bundler
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [v2.0.4] -
2
+
3
+ - Add Rails 3 support
4
+ - [#175](https://github.com/phstc/shoryuken/pull/175)
5
+
6
+ - Allow symbol as a queue name in shoryuken_options
7
+ - [#177](https://github.com/phstc/shoryuken/pull/177)
8
+
9
+ - Make sure bundler is always updated on Travis CI
10
+ - [#176](https://github.com/phstc/shoryuken/pull/176)
11
+
12
+ - Add Rails 5 compatibility
13
+ - [#174](https://github.com/phstc/shoryuken/pull/174)
14
+
1
15
  ## [v2.0.3] - 2015-12-30
2
16
 
3
17
  - Allow multiple queues per worker
@@ -1,47 +1,69 @@
1
- begin
2
- require 'active_support/core_ext/hash/keys'
3
- require 'active_support/core_ext/hash/deep_merge'
4
- rescue LoadError
5
- class Hash
6
- def stringify_keys
7
- keys.each do |key|
8
- self[key.to_s] = delete(key)
1
+ module Shoryuken
2
+ module HashExt
3
+ module StringifyKeys
4
+ def stringify_keys
5
+ keys.each do |key|
6
+ self[key.to_s] = delete(key)
7
+ end
8
+ self
9
+ end
10
+ end
11
+
12
+ module SymbolizeKeys
13
+ def symbolize_keys
14
+ keys.each do |key|
15
+ self[(key.to_sym rescue key) || key] = delete(key)
16
+ end
17
+ self
9
18
  end
10
- self
11
- end if !{}.respond_to?(:stringify_keys)
19
+ end
20
+
21
+ module DeepSymbolizeKeys
22
+ def deep_symbolize_keys
23
+ keys.each do |key|
24
+ value = delete(key)
25
+ self[(key.to_sym rescue key) || key] = value
12
26
 
13
- def symbolize_keys
14
- keys.each do |key|
15
- self[(key.to_sym rescue key) || key] = delete(key)
27
+ value.deep_symbolize_keys if value.is_a? Hash
28
+ end
29
+ self
16
30
  end
17
- self
18
- end if !{}.respond_to?(:symbolize_keys)
31
+ end
32
+ end
19
33
 
20
- def deep_symbolize_keys
21
- keys.each do |key|
22
- value = delete(key)
23
- self[(key.to_sym rescue key) || key] = value
34
+ module StringExt
35
+ module Constantize
36
+ def constantize
37
+ names = self.split('::')
38
+ names.shift if names.empty? || names.first.empty?
24
39
 
25
- value.deep_symbolize_keys if value.is_a? Hash
40
+ constant = Object
41
+ names.each do |name|
42
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
43
+ end
44
+ constant
26
45
  end
27
- self
28
- end if !{}.respond_to?(:deep_symbolize_keys)
46
+ end
29
47
  end
30
48
  end
31
49
 
50
+ begin
51
+ require 'active_support/core_ext/hash/keys'
52
+ require 'active_support/core_ext/hash/deep_merge'
53
+ rescue LoadError
54
+ end
55
+
56
+ class Hash
57
+ include Shoryuken::HashExt::StringifyKeys unless method_defined?(:stringify_keys)
58
+ include Shoryuken::HashExt::SymbolizeKeys unless method_defined?(:symbolize_keys)
59
+ include Shoryuken::HashExt::DeepSymbolizeKeys unless method_defined?(:deep_symbolize_keys)
60
+ end
61
+
32
62
  begin
33
63
  require 'active_support/core_ext/string/inflections'
34
64
  rescue LoadError
35
- class String
36
- def constantize
37
- names = self.split('::')
38
- names.shift if names.empty? || names.first.empty?
39
-
40
- constant = Object
41
- names.each do |name|
42
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
43
- end
44
- constant
45
- end
46
- end if !"".respond_to?(:constantize)
65
+ end
66
+
67
+ class String
68
+ include Shoryuken::StringExt::Constantize unless method_defined?(:constantize)
47
69
  end
@@ -166,7 +166,7 @@ module Shoryuken
166
166
  begin
167
167
  Shoryuken::Client.queues queue
168
168
  rescue Aws::SQS::Errors::NonExistentQueue
169
- Shoryuken.logger.warn { "AWS Queue '#{queue}' does not exist" }
169
+ Shoryuken.logger.warn { "The specified queue '#{queue}' does not exist" }
170
170
  end
171
171
  end
172
172
  end
@@ -16,44 +16,57 @@ module ActiveJob
16
16
  # Rails.application.config.active_job.queue_adapter = :shoryuken
17
17
  class ShoryukenAdapter
18
18
  class << self
19
- def enqueue(job) #:nodoc:
20
- register_worker!(job)
19
+ def instance
20
+ # https://github.com/phstc/shoryuken/pull/174#issuecomment-174555657
21
+ @instance ||= new
22
+ end
21
23
 
22
- queue = Shoryuken::Client.queues(job.queue_name)
23
- queue.send_message(message(job))
24
+ def enqueue(job)
25
+ instance.enqueue(job)
24
26
  end
25
27
 
26
- def enqueue_at(job, timestamp) #:nodoc:
27
- register_worker!(job)
28
+ def enqueue_at(job, timestamp)
29
+ instance.enqueue(job, timestamp)
30
+ end
31
+ end
28
32
 
29
- delay = (timestamp - Time.current.to_f).round
30
- raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
33
+ def enqueue(job) #:nodoc:
34
+ register_worker!(job)
31
35
 
32
- queue = Shoryuken::Client.queues(job.queue_name)
33
- queue.send_message(message(job, delay_seconds: delay))
34
- end
36
+ queue = Shoryuken::Client.queues(job.queue_name)
37
+ queue.send_message(message(job))
38
+ end
35
39
 
36
- private
40
+ def enqueue_at(job, timestamp) #:nodoc:
41
+ register_worker!(job)
37
42
 
38
- def message(job, options = {})
39
- body = job.serialize
43
+ delay = (timestamp - Time.current.to_f).round
44
+ raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
40
45
 
41
- { message_body: body,
42
- message_attributes: message_attributes }.merge(options)
43
- end
46
+ queue = Shoryuken::Client.queues(job.queue_name)
47
+ queue.send_message(message(job, delay_seconds: delay))
48
+ end
44
49
 
45
- def register_worker!(job)
46
- Shoryuken.register_worker(job.queue_name, JobWrapper)
47
- end
50
+ private
51
+
52
+ def message(job, options = {})
53
+ body = job.serialize
54
+
55
+ { message_body: body,
56
+ message_attributes: message_attributes }.merge(options)
57
+ end
48
58
 
49
- def message_attributes
50
- @message_attributes ||= {
51
- 'shoryuken_class' => {
52
- string_value: JobWrapper.to_s,
53
- data_type: 'String'
54
- }
59
+ def register_worker!(job)
60
+ Shoryuken.register_worker(job.queue_name, JobWrapper)
61
+ end
62
+
63
+ def message_attributes
64
+ @message_attributes ||= {
65
+ 'shoryuken_class' => {
66
+ string_value: JobWrapper.to_s,
67
+ data_type: 'String'
55
68
  }
56
- end
69
+ }
57
70
  end
58
71
 
59
72
  class JobWrapper #:nodoc:
@@ -5,7 +5,11 @@ module Shoryuken
5
5
  def initialize(client, name)
6
6
  self.name = name
7
7
  self.client = client
8
- self.url = client.get_queue_url(queue_name: name).queue_url
8
+ begin
9
+ self.url = client.get_queue_url(queue_name: name).queue_url
10
+ rescue Aws::SQS::Errors::NonExistentQueue => e
11
+ raise e, "The specified queue '#{name}' does not exist"
12
+ end
9
13
  end
10
14
 
11
15
  def visibility_timeout
@@ -1,3 +1,3 @@
1
1
  module Shoryuken
2
- VERSION = '2.0.3'
2
+ VERSION = '2.0.4'
3
3
  end
@@ -68,6 +68,13 @@ module Shoryuken
68
68
  @shoryuken_options['queue'] = queue
69
69
  end
70
70
 
71
+ case @shoryuken_options['queue']
72
+ when Array
73
+ @shoryuken_options['queue'].map!(&:to_s)
74
+ when Symbol
75
+ @shoryuken_options['queue'] = @shoryuken_options['queue'].to_s
76
+ end
77
+
71
78
  [@shoryuken_options['queue']].flatten.compact.each(&method(:register_worker))
72
79
  end
73
80
 
@@ -1,6 +1,34 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'core_ext' do
3
+ RSpec.describe 'Core Extensions' do
4
+ describe Hash do
5
+ describe 'stringify_keys' do
6
+ it 'converts keys into strings' do
7
+ expect({ :key1 => 'value1', 'key2' => 'value2' }.stringify_keys).to eq('key1' => 'value1', 'key2' => 'value2')
8
+ end
9
+ end
10
+
11
+ describe 'symbolize_keys' do
12
+ it 'converts keys into strings' do
13
+ expect({ :key1 => 'value1', 'key2' => 'value2' }.symbolize_keys).to eq(:key1 => 'value1', key2: 'value2')
14
+ end
15
+ end
16
+
17
+ describe 'deep_symbolize_keys' do
18
+ it 'converts keys into strings' do
19
+ expect({ :key1 => 'value1',
20
+ 'key2' => 'value2',
21
+ 'key3' => {
22
+ 'key31' => { 'key311' => 'value311' },
23
+ 'key32' => 'value32' } }.deep_symbolize_keys).to eq({ :key1 => 'value1',
24
+ :key2 => 'value2',
25
+ :key3 => { :key31 =>
26
+ { :key311 => 'value311' },
27
+ :key32 => 'value32' } })
28
+ end
29
+ end
30
+ end
31
+
4
32
  describe String do
5
33
  describe '#constantize' do
6
34
  class HelloWorld; end
@@ -142,6 +142,28 @@ RSpec.describe 'Shoryuken::Worker' do
142
142
  expect(GlobalDefaultsTestWorker.get_shoryuken_options['auto_delete']).to eq true
143
143
  expect(GlobalDefaultsTestWorker.get_shoryuken_options['batch']).to eq false
144
144
  end
145
+
146
+ it 'accepts a symbol as a queue and converts to string' do
147
+ class SymbolQueueTestWorker
148
+ include Shoryuken::Worker
149
+
150
+ shoryuken_options queue: :default
151
+ end
152
+
153
+ expect(SymbolQueueTestWorker.get_shoryuken_options['queue']).to eq 'default'
154
+ end
155
+
156
+ it 'accepts an array that contains symbols as a queue and converts to string' do
157
+ class WorkerMultipleSymbolQueues
158
+ include Shoryuken::Worker
159
+
160
+ shoryuken_options queue: %i[symbol_queue1 symbol_queue2 symbol_queue3]
161
+ end
162
+
163
+ expect(Shoryuken.worker_registry.workers('symbol_queue1')).to eq([WorkerMultipleSymbolQueues])
164
+ expect(Shoryuken.worker_registry.workers('symbol_queue2')).to eq([WorkerMultipleSymbolQueues])
165
+ expect(Shoryuken.worker_registry.workers('symbol_queue3')).to eq([WorkerMultipleSymbolQueues])
166
+ end
145
167
  end
146
168
 
147
169
  describe '.server_middleware' 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.3
4
+ version: 2.0.4
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-12-30 00:00:00.000000000 Z
11
+ date: 2016-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler