diff --git a/lib/sidekiq/client.rb b/lib/sidekiq/client.rb index ab9dfd37..2fe87b99 100644 --- a/lib/sidekiq/client.rb +++ b/lib/sidekiq/client.rb @@ -67,7 +67,8 @@ module Sidekiq # push('queue' => 'my_queue', 'class' => MyWorker, 'args' => ['foo', 1, :bat => 'bar']) # def push(item) - payload = payload_for_push(item) + normed = normalize_item(item) + payload = process_single(item["class"], normed) if payload raw_push([payload]) @@ -75,9 +76,19 @@ module Sidekiq end end - def payload_for_push(item) + def perform_inline(item) normed = normalize_item(item) - process_single(item["class"], normed) + payload = process_single(item["class"], normed) + + msg = Sidekiq.load_json(Sidekiq.dump_json(payload)) + klass = msg['class'].constantize + job = klass.new + job.jid = msg['jid'] + msg['id'] ||= SecureRandom.hex(12) + + Sidekiq.server_middleware.invoke(job, msg, msg['queue']) do + job.perform(*msg['args']) + end end ## diff --git a/lib/sidekiq/worker.rb b/lib/sidekiq/worker.rb index 2d1c9e6a..438eb0b8 100644 --- a/lib/sidekiq/worker.rb +++ b/lib/sidekiq/worker.rb @@ -194,17 +194,7 @@ module Sidekiq # Inline execution of job's perform method after passing through Sidekiq.client_middleware and Sidekiq.server_middleware def perform_inline(*args) item = @opts.merge('args' => args, 'class' => @klass).transform_keys(&:to_s) - payload = Sidekiq::Client.new.payload_for_push(item) - - msg = Sidekiq.load_json(Sidekiq.dump_json(payload)) - klass = msg['class'].constantize - job = klass.new - job.jid = msg['jid'] - msg['id'] ||= SecureRandom.hex(12) - - Sidekiq.server_middleware.invoke(job, msg, msg['queue']) do - job.perform(*msg['args']) - end + Sidekiq::Client.new.perform_inline(item) end def perform_bulk(args, batch_size: 1_000) @@ -259,7 +249,8 @@ module Sidekiq # Inline execution of job's perform method after passing through Sidekiq.client_middleware and Sidekiq.server_middleware def perform_inline(*args) - set({}).perform_inline(*args) + item = {"class" => self, "args" => args } + Sidekiq::Client.new.perform_inline(item) end ##