Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple queues per worker support #164

Merged
merged 1 commit into from
Dec 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions lib/shoryuken/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,7 @@ def server_middleware

def shoryuken_options(opts = {})
@shoryuken_options = get_shoryuken_options.merge(stringify_keys(opts || {}))
queue = @shoryuken_options['queue']
if queue.respond_to? :call
queue = queue.call
@shoryuken_options['queue'] = queue
end

Shoryuken.register_worker(queue, self)
normalize_worker_queue!
end

def auto_visibility_timeout?
Expand All @@ -64,6 +58,22 @@ def stringify_keys(hash) # :nodoc:
end
hash
end

private

def normalize_worker_queue!
queue = @shoryuken_options['queue']
if queue.respond_to? :call
queue = queue.call
@shoryuken_options['queue'] = queue
end

[@shoryuken_options['queue']].flatten.compact.each(&method(:register_worker))
end

def register_worker(queue)
Shoryuken.register_worker(queue, self)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/integration/launcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'shoryuken/manager'
require 'shoryuken/launcher'

describe Shoryuken::Launcher do
RSpec.describe Shoryuken::Launcher do
describe 'Consuming messages', slow: :true do
before do
Shoryuken.options[:aws][:receive_message] = { wait_time_seconds: 5 }
Expand Down
16 changes: 14 additions & 2 deletions spec/shoryuken/worker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'spec_helper'

describe 'Shoryuken::Worker' do
RSpec.describe 'Shoryuken::Worker' do
let(:sqs_queue) { double 'SQS Queue' }
let(:queue) { 'default' }

Expand Down Expand Up @@ -103,7 +103,7 @@
expect(Shoryuken.worker_registry.workers('default')).to eq([TestWorker])
end

it 'accepts a block as queue name' do
it 'accepts a block as a queue' do
$queue_prefix = 'production'

class NewTestWorker
Expand All @@ -116,6 +116,18 @@ class NewTestWorker
expect(NewTestWorker.get_shoryuken_options['queue']).to eq 'production_default'
end

it 'accepts an array as a queue' do
class WorkerMultipleQueues
include Shoryuken::Worker

shoryuken_options queue: %w[queue1 queue2 queue3]
end

expect(Shoryuken.worker_registry.workers('queue1')).to eq([WorkerMultipleQueues])
expect(Shoryuken.worker_registry.workers('queue2')).to eq([WorkerMultipleQueues])
expect(Shoryuken.worker_registry.workers('queue3')).to eq([WorkerMultipleQueues])
end

it 'is possible to configure the global defaults' do
queue = SecureRandom.uuid
Shoryuken.default_worker_options['queue'] = queue
Expand Down