Skip to content

Commit

Permalink
Merge pull request #147 from bobbrez/bobbrez/allow_queue_option
Browse files Browse the repository at this point in the history
Enable override the default queue with a :queue option
  • Loading branch information
phstc committed Oct 27, 2015
2 parents 88d0504 + 18b1fdf commit 3d9e11f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/shoryuken/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ def self.included(base)

module ClassMethods
def perform_async(body, options = {})
options ||= {}
options[:message_attributes] ||= {}
options[:message_attributes]['shoryuken_class'] = {
string_value: self.to_s,
Expand All @@ -15,7 +14,9 @@ def perform_async(body, options = {})

options[:message_body] = body

Shoryuken::Client.queues(get_shoryuken_options['queue']).send_message(options)
queue = options.delete(:queue) || get_shoryuken_options['queue']

Shoryuken::Client.queues(queue).send_message(options)
end

def perform_in(interval, body, options = {})
Expand Down
17 changes: 17 additions & 0 deletions spec/shoryuken/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@

TestWorker.perform_async('delayed message', delay_seconds: 60)
end

it 'accepts an `queue` option' do
new_queue = 'some_different_queue'

expect(Shoryuken::Client).to receive(:queues).with(new_queue).and_return(sqs_queue)

expect(sqs_queue).to receive(:send_message).with(
message_attributes: {
'shoryuken_class' => {
string_value: TestWorker.to_s,
data_type: 'String'
}
},
message_body: 'delayed message')

TestWorker.perform_async('delayed message', queue: new_queue)
end
end

describe '.shoryuken_options' do
Expand Down

0 comments on commit 3d9e11f

Please sign in to comment.