shoryuken 2.0.3 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/CHANGELOG.md +14 -0
- data/lib/shoryuken/core_ext.rb +56 -34
- data/lib/shoryuken/environment_loader.rb +1 -1
- data/lib/shoryuken/extensions/active_job_adapter.rb +40 -27
- data/lib/shoryuken/queue.rb +5 -1
- data/lib/shoryuken/version.rb +1 -1
- data/lib/shoryuken/worker.rb +7 -0
- data/spec/shoryuken/core_ext_spec.rb +29 -1
- data/spec/shoryuken/worker_spec.rb +22 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25d7b8d6df3ab9ede1f0d7a6aba01d18e2a102f2
|
4
|
+
data.tar.gz: bf26e631ee57665f7b18d0a314259b48e71951cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edfb890c3b31a38252bfecfd5f0f1c4d98b31c892f12106136fd91c973434f544e76c1ca48c860f2cd4f1065342231ca1dbd3a3f8752eb49613be45b57ce4c87
|
7
|
+
data.tar.gz: 3c36a03cb7bc41ce4038c5942b87f3e5b087d08a4e26e9387f9dc3222bbd4e50840af7ddd68f3b073712de5d8a629d57d29ec9387e855c16499183983fea0e04
|
data/.travis.yml
CHANGED
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
|
data/lib/shoryuken/core_ext.rb
CHANGED
@@ -1,47 +1,69 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
self
|
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
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
self
|
27
|
+
value.deep_symbolize_keys if value.is_a? Hash
|
28
|
+
end
|
29
|
+
self
|
16
30
|
end
|
17
|
-
|
18
|
-
|
31
|
+
end
|
32
|
+
end
|
19
33
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
self
|
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
|
-
|
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
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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 { "
|
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
|
20
|
-
|
19
|
+
def instance
|
20
|
+
# https://github.com/phstc/shoryuken/pull/174#issuecomment-174555657
|
21
|
+
@instance ||= new
|
22
|
+
end
|
21
23
|
|
22
|
-
|
23
|
-
|
24
|
+
def enqueue(job)
|
25
|
+
instance.enqueue(job)
|
24
26
|
end
|
25
27
|
|
26
|
-
def enqueue_at(job, timestamp)
|
27
|
-
|
28
|
+
def enqueue_at(job, timestamp)
|
29
|
+
instance.enqueue(job, timestamp)
|
30
|
+
end
|
31
|
+
end
|
28
32
|
|
29
|
-
|
30
|
-
|
33
|
+
def enqueue(job) #:nodoc:
|
34
|
+
register_worker!(job)
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
36
|
+
queue = Shoryuken::Client.queues(job.queue_name)
|
37
|
+
queue.send_message(message(job))
|
38
|
+
end
|
35
39
|
|
36
|
-
|
40
|
+
def enqueue_at(job, timestamp) #:nodoc:
|
41
|
+
register_worker!(job)
|
37
42
|
|
38
|
-
|
39
|
-
|
43
|
+
delay = (timestamp - Time.current.to_f).round
|
44
|
+
raise 'The maximum allowed delay is 15 minutes' if delay > 15.minutes
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
46
|
+
queue = Shoryuken::Client.queues(job.queue_name)
|
47
|
+
queue.send_message(message(job, delay_seconds: delay))
|
48
|
+
end
|
44
49
|
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
69
|
+
}
|
57
70
|
end
|
58
71
|
|
59
72
|
class JobWrapper #:nodoc:
|
data/lib/shoryuken/queue.rb
CHANGED
@@ -5,7 +5,11 @@ module Shoryuken
|
|
5
5
|
def initialize(client, name)
|
6
6
|
self.name = name
|
7
7
|
self.client = client
|
8
|
-
|
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
|
data/lib/shoryuken/version.rb
CHANGED
data/lib/shoryuken/worker.rb
CHANGED
@@ -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 '
|
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.
|
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:
|
11
|
+
date: 2016-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|