Skip to content

Commit

Permalink
Merge pull request #326 from phstc/remove-deprecation-warnings-325
Browse files Browse the repository at this point in the history
Remove deprecation warnings


Fix #325
  • Loading branch information
phstc authored Mar 2, 2017
2 parents 477c5f5 + c59656f commit 1bd724c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 74 deletions.
19 changes: 0 additions & 19 deletions lib/shoryuken/environment_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def load
require_workers
validate_queues
validate_workers
patch_deprecated_workers
end

private
Expand Down Expand Up @@ -108,24 +107,6 @@ def parse_queues
end
end

def patch_deprecated_workers
Shoryuken.worker_registry.queues.each do |queue|
Shoryuken.worker_registry.workers(queue).each do |worker_class|
if worker_class.instance_method(:perform).arity == 1
Shoryuken.logger.warn { "[DEPRECATION] #{worker_class.name}#perform(sqs_msg) is deprecated. Please use #{worker_class.name}#perform(sqs_msg, body)" }

worker_class.class_eval do
alias_method :deprecated_perform, :perform

def perform(sqs_msg, body = nil)
deprecated_perform(sqs_msg)
end
end
end
end
end
end

def require_workers
required = Shoryuken.options[:require]

Expand Down
17 changes: 4 additions & 13 deletions lib/shoryuken/message.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,10 @@ class Message
attr_accessor :client, :queue_url, :queue_name, :data

def initialize(client, queue, data)
self.client = client
self.data = data

if queue.is_a?(Shoryuken::Queue)
self.queue_url = queue.url
self.queue_name = queue.name
else
# TODO: Remove next major release
Shoryuken.logger.warn do
'[DEPRECATION] Passing a queue url into Shoryuken::Message is deprecated, please pass the queue itself'
end
self.queue_url = queue
end
self.client = client
self.data = data
self.queue_url = queue.url
self.queue_name = queue.name
end

def delete
Expand Down
19 changes: 1 addition & 18 deletions lib/shoryuken/middleware/chain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,32 +102,15 @@ def invoke(*args, &final_action)

class Entry
attr_reader :klass

def initialize(klass, *args)
@klass = klass
@args = args

patch_deprecated_middleware!(klass)
end

def make_new
@klass.new(*@args)
end

private

def patch_deprecated_middleware!(klass)
if klass.instance_method(:call).arity == 3
Shoryuken.logger.warn { "[DEPRECATION] #{klass.name}#call(worker_instance, queue, sqs_msg) is deprecated. Please use #{klass.name}#call(worker_instance, queue, sqs_msg, body)" }

klass.class_eval do
alias_method :deprecated_call, :call

def call(worker_instance, queue, sqs_msg, body = nil, &block)
deprecated_call(worker_instance, queue, sqs_msg, &block)
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions spec/integration/launcher_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'shoryuken/manager'
require 'shoryuken/launcher'
require 'securerandom'

RSpec.describe Shoryuken::Launcher do
describe 'Consuming messages', slow: :true do
Expand Down
24 changes: 0 additions & 24 deletions spec/shoryuken/middleware/chain_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,4 @@ def call(*args); end
expect(final_action).to eq nil
expect(recorder).to eq []
end

class DeprecatedMiddleware
def call(worker_instance, queue, sqs_msg)
@@success = true
end

def self.success?
!!@@success
end
end

it 'patches deprecated middleware' do
subject.clear

expect(Shoryuken.logger).to receive(:warn) do |&block|
expect(block.call).to eq('[DEPRECATION] DeprecatedMiddleware#call(worker_instance, queue, sqs_msg) is deprecated. Please use DeprecatedMiddleware#call(worker_instance, queue, sqs_msg, body)')
end

subject.add DeprecatedMiddleware

subject.invoke TestWorker, 'test', double('SQS msg', body: 'test'), 'test'

expect(DeprecatedMiddleware.success?).to eq true
end
end

0 comments on commit 1bd724c

Please sign in to comment.