shoryuken 0.0.4 → 0.0.5

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.
@@ -83,7 +83,7 @@ describe 'Shoryuken::Worker' do
83
83
 
84
84
  describe '.shoryuken_options' do
85
85
  it 'registers a worker' do
86
- expect(Shoryuken.workers['default']).to eq TestWorker
86
+ expect(Shoryuken.worker_registry.workers('default')).to eq([TestWorker])
87
87
  end
88
88
 
89
89
  it 'accepts a block as queue name' do
@@ -95,8 +95,106 @@ describe 'Shoryuken::Worker' do
95
95
  shoryuken_options queue: ->{ "#{$queue_prefix}_default" }
96
96
  end
97
97
 
98
- expect(Shoryuken.workers['production_default']).to eq NewTestWorker
98
+ expect(Shoryuken.worker_registry.workers('production_default')).to eq([NewTestWorker])
99
99
  expect(NewTestWorker.get_shoryuken_options['queue']).to eq 'production_default'
100
100
  end
101
+
102
+ it 'is possible to configure the global defaults' do
103
+ queue = SecureRandom.uuid
104
+ Shoryuken.default_worker_options['queue'] = queue
105
+
106
+ class GlobalDefaultsTestWorker
107
+ include Shoryuken::Worker
108
+
109
+ shoryuken_options auto_delete: true
110
+ end
111
+
112
+ expect(GlobalDefaultsTestWorker.get_shoryuken_options['queue']).to eq queue
113
+ expect(GlobalDefaultsTestWorker.get_shoryuken_options['auto_delete']).to eq true
114
+ expect(GlobalDefaultsTestWorker.get_shoryuken_options['batch']).to eq false
115
+ end
116
+ end
117
+
118
+ describe '.server_middleware' do
119
+ before do
120
+ class FakeMiddleware
121
+ def call(*args)
122
+ yield
123
+ end
124
+ end
125
+ end
126
+
127
+ context 'no middleware is defined in the worker' do
128
+ it 'returns the list of global middlewares' do
129
+ expect(TestWorker.server_middleware).to satisfy do |chain|
130
+ chain.exists?(Shoryuken::Middleware::Server::Timing)
131
+ end
132
+
133
+ expect(TestWorker.server_middleware).to satisfy do |chain|
134
+ chain.exists?(Shoryuken::Middleware::Server::AutoDelete)
135
+ end
136
+ end
137
+ end
138
+
139
+ context 'the worker clears the middleware chain' do
140
+ before do
141
+ class NewTestWorker2
142
+ include Shoryuken::Worker
143
+
144
+ server_middleware do |chain|
145
+ chain.clear
146
+ end
147
+ end
148
+ end
149
+
150
+ it 'returns an empty list' do
151
+ expect(NewTestWorker2.server_middleware.entries).to be_empty
152
+ end
153
+
154
+ it 'does not affect the global middleware chain' do
155
+ expect(Shoryuken.server_middleware.entries).not_to be_empty
156
+ end
157
+ end
158
+
159
+ context 'the worker modifies the chain' do
160
+ before do
161
+ class NewTestWorker3
162
+ include Shoryuken::Worker
163
+
164
+ server_middleware do |chain|
165
+ chain.remove Shoryuken::Middleware::Server::Timing
166
+ chain.insert_before Shoryuken::Middleware::Server::AutoDelete, FakeMiddleware
167
+ end
168
+ end
169
+ end
170
+
171
+ it 'returns the combined global and worker middlewares' do
172
+ expect(NewTestWorker3.server_middleware).not_to satisfy do |chain|
173
+ chain.exists?(Shoryuken::Middleware::Server::Timing)
174
+ end
175
+
176
+ expect(NewTestWorker3.server_middleware).to satisfy do |chain|
177
+ chain.exists?(FakeMiddleware)
178
+ end
179
+
180
+ expect(NewTestWorker3.server_middleware).to satisfy do |chain|
181
+ chain.exists?(Shoryuken::Middleware::Server::AutoDelete)
182
+ end
183
+ end
184
+
185
+ it 'does not affect the global middleware chain' do
186
+ expect(Shoryuken.server_middleware).to satisfy do |chain|
187
+ chain.exists?(Shoryuken::Middleware::Server::Timing)
188
+ end
189
+
190
+ expect(Shoryuken.server_middleware).to satisfy do |chain|
191
+ chain.exists?(Shoryuken::Middleware::Server::AutoDelete)
192
+ end
193
+
194
+ expect(Shoryuken.server_middleware).not_to satisfy do |chain|
195
+ chain.exists?(FakeMiddleware)
196
+ end
197
+ end
198
+ end
101
199
  end
102
200
  end
@@ -3,22 +3,22 @@ require 'spec_helper'
3
3
  describe Shoryuken do
4
4
  describe '.register_worker' do
5
5
  it 'registers a worker' do
6
- described_class.workers.clear
6
+ described_class.worker_registry.clear
7
7
  described_class.register_worker('default', TestWorker)
8
- expect(described_class.workers).to eq('default' => TestWorker)
8
+ expect(described_class.worker_registry.workers('default')).to eq([TestWorker])
9
9
  end
10
10
 
11
11
  it 'registers a batchable worker' do
12
- described_class.workers.clear
12
+ described_class.worker_registry.clear
13
13
  TestWorker.get_shoryuken_options['batch'] = true
14
14
  described_class.register_worker('default', TestWorker)
15
- expect(described_class.workers).to eq('default' => TestWorker)
15
+ expect(described_class.worker_registry.workers('default')).to eq([TestWorker])
16
16
  end
17
17
 
18
18
  it 'allows multiple workers' do
19
- described_class.workers.clear
19
+ described_class.worker_registry.clear
20
20
  described_class.register_worker('default', TestWorker)
21
- expect(described_class.workers).to eq('default' => TestWorker)
21
+ expect(described_class.worker_registry.workers('default')).to eq([TestWorker])
22
22
 
23
23
  class Test2Worker
24
24
  include Shoryuken::Worker
@@ -28,11 +28,11 @@ describe Shoryuken do
28
28
  def perform(sqs_msg, body); end
29
29
  end
30
30
 
31
- expect(described_class.workers).to eq('default' => Test2Worker)
31
+ expect(described_class.worker_registry.workers('default')).to eq([Test2Worker])
32
32
  end
33
33
 
34
34
  it 'raises an exception when mixing batchable with non batchable' do
35
- described_class.workers.clear
35
+ described_class.worker_registry.clear
36
36
  TestWorker.get_shoryuken_options['batch'] = true
37
37
  described_class.register_worker('default', TestWorker)
38
38
 
@@ -45,7 +45,7 @@ describe Shoryuken do
45
45
  def perform(sqs_msg, body); end
46
46
  end
47
47
  }.to raise_error("Could not register BatchableWorker for 'default', because TestWorker is already registered for this queue, " \
48
- "and Shoryuken doesn't support a batchable worker for a queue with multiple workers")
48
+ "and Shoryuken doesn't support a batchable worker for a queue with multiple workers.")
49
49
  end
50
50
  end
51
51
  end
data/spec/spec_helper.rb CHANGED
@@ -51,7 +51,7 @@ RSpec.configure do |config|
51
51
  TestWorker.get_shoryuken_options.clear
52
52
  TestWorker.get_shoryuken_options['queue'] = 'default'
53
53
 
54
- Shoryuken.workers.clear
54
+ Shoryuken.worker_registry.clear
55
55
  Shoryuken.register_worker('default', TestWorker)
56
56
  end
57
57
  end
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: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-22 00:00:00.000000000 Z
11
+ date: 2015-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - ~>
88
88
  - !ruby/object:Gem::Version
89
- version: 0.15.2
89
+ version: 0.16.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ~>
95
95
  - !ruby/object:Gem::Version
96
- version: 0.15.2
96
+ version: 0.16.0
97
97
  description: Shoryuken is a super efficient AWS SQS thread based message processor
98
98
  email:
99
99
  - pablo@pablocantero.com
@@ -116,6 +116,8 @@ files:
116
116
  - lib/shoryuken/cli.rb
117
117
  - lib/shoryuken/client.rb
118
118
  - lib/shoryuken/core_ext.rb
119
+ - lib/shoryuken/default_worker_registry.rb
120
+ - lib/shoryuken/extensions/active_job_adapter.rb
119
121
  - lib/shoryuken/fetcher.rb
120
122
  - lib/shoryuken/launcher.rb
121
123
  - lib/shoryuken/logging.rb
@@ -128,12 +130,13 @@ files:
128
130
  - lib/shoryuken/util.rb
129
131
  - lib/shoryuken/version.rb
130
132
  - lib/shoryuken/worker.rb
131
- - lib/shoryuken/worker_loader.rb
133
+ - lib/shoryuken/worker_registry.rb
132
134
  - shoryuken.gemspec
133
135
  - shoryuken.jpg
134
136
  - spec/integration/launcher_spec.rb
135
137
  - spec/shoryuken/client_spec.rb
136
138
  - spec/shoryuken/core_ext_spec.rb
139
+ - spec/shoryuken/default_worker_registry_spec.rb
137
140
  - spec/shoryuken/fetcher_spec.rb
138
141
  - spec/shoryuken/manager_spec.rb
139
142
  - spec/shoryuken/middleware/chain_spec.rb
@@ -141,13 +144,12 @@ files:
141
144
  - spec/shoryuken/middleware/server/timing_spec.rb
142
145
  - spec/shoryuken/processor_spec.rb
143
146
  - spec/shoryuken/util_spec.rb
144
- - spec/shoryuken/worker_loader_spec.rb
145
147
  - spec/shoryuken/worker_spec.rb
146
148
  - spec/shoryuken_spec.rb
147
149
  - spec/spec_helper.rb
148
150
  homepage: https://github.com/phstc/shoryuken
149
151
  licenses:
150
- - MIT
152
+ - LGPL-3.0
151
153
  metadata: {}
152
154
  post_install_message:
153
155
  rdoc_options: []
@@ -173,6 +175,7 @@ test_files:
173
175
  - spec/integration/launcher_spec.rb
174
176
  - spec/shoryuken/client_spec.rb
175
177
  - spec/shoryuken/core_ext_spec.rb
178
+ - spec/shoryuken/default_worker_registry_spec.rb
176
179
  - spec/shoryuken/fetcher_spec.rb
177
180
  - spec/shoryuken/manager_spec.rb
178
181
  - spec/shoryuken/middleware/chain_spec.rb
@@ -180,7 +183,6 @@ test_files:
180
183
  - spec/shoryuken/middleware/server/timing_spec.rb
181
184
  - spec/shoryuken/processor_spec.rb
182
185
  - spec/shoryuken/util_spec.rb
183
- - spec/shoryuken/worker_loader_spec.rb
184
186
  - spec/shoryuken/worker_spec.rb
185
187
  - spec/shoryuken_spec.rb
186
188
  - spec/spec_helper.rb
@@ -1,17 +0,0 @@
1
- module Shoryuken
2
- class WorkerLoader
3
- class << self
4
- def call(queue, sqs_msg)
5
- # missing `try?` - yes, I'm
6
- worker_class = !sqs_msg.is_a?(Array) &&
7
- sqs_msg.message_attributes &&
8
- sqs_msg.message_attributes['shoryuken_class'] &&
9
- sqs_msg.message_attributes['shoryuken_class'][:string_value]
10
-
11
- worker_class = (worker_class.constantize rescue nil) || Shoryuken.workers[queue]
12
-
13
- worker_class.new
14
- end
15
- end
16
- end
17
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Shoryuken::WorkerLoader do
4
- let(:queue) { 'default' }
5
- let(:sqs_msg) { double AWS::SQS::ReceivedMessage, id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e', body: 'test', message_attributes: { } }
6
-
7
- describe '.call' do
8
- it 'returns the worker using `Shoryuken.workers`' do
9
- expect(described_class.call(queue, sqs_msg)).to be_an_instance_of TestWorker
10
- end
11
-
12
- context 'when `message_attributes`' do
13
- let(:sqs_msg) { double AWS::SQS::ReceivedMessage, id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e', body: 'test', message_attributes: {
14
- 'shoryuken_class' => {
15
- string_value: TestWorker.to_s,
16
- data_type: 'String'
17
- }
18
- } }
19
-
20
- it 'returns the worker using `message_attributes`' do
21
- Shoryuken.workers.clear
22
-
23
- expect(described_class.call(queue, sqs_msg)).to be_an_instance_of TestWorker
24
- end
25
- end
26
- end
27
- end