Skip to content

Commit

Permalink
Merge pull request #177 from serihiro/convert-queue-name-to-string
Browse files Browse the repository at this point in the history
Allow symbol as a queue name in shoryuken_options
  • Loading branch information
phstc committed Jan 29, 2016
2 parents 51f5243 + 93642ba commit 9f9ceed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/shoryuken/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ def normalize_worker_queue!
@shoryuken_options['queue'] = queue
end

case @shoryuken_options['queue']
when Array
@shoryuken_options['queue'].map!(&:to_s)
when Symbol
@shoryuken_options['queue'] = @shoryuken_options['queue'].to_s
end

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

Expand Down
22 changes: 22 additions & 0 deletions spec/shoryuken/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ class GlobalDefaultsTestWorker
expect(GlobalDefaultsTestWorker.get_shoryuken_options['auto_delete']).to eq true
expect(GlobalDefaultsTestWorker.get_shoryuken_options['batch']).to eq false
end

it 'accepts a symbol as a queue and converts to string' do
class SymbolQueueTestWorker
include Shoryuken::Worker

shoryuken_options queue: :default
end

expect(SymbolQueueTestWorker.get_shoryuken_options['queue']).to eq 'default'
end

it 'accepts an array that contains symbols as a queue and converts to string' do
class WorkerMultipleSymbolQueues
include Shoryuken::Worker

shoryuken_options queue: %i[symbol_queue1 symbol_queue2 symbol_queue3]
end

expect(Shoryuken.worker_registry.workers('symbol_queue1')).to eq([WorkerMultipleSymbolQueues])
expect(Shoryuken.worker_registry.workers('symbol_queue2')).to eq([WorkerMultipleSymbolQueues])
expect(Shoryuken.worker_registry.workers('symbol_queue3')).to eq([WorkerMultipleSymbolQueues])
end
end

describe '.server_middleware' do
Expand Down

0 comments on commit 9f9ceed

Please sign in to comment.