1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

chore: move perform_inline to Sidekiq::Client to avoid unncessary set({})

This commit is contained in:
Hasan Kumar 2021-11-16 03:10:38 +05:30
parent 2898a715d7
commit c950470cbc
No known key found for this signature in database
GPG key ID: A110EFA955BA9314
2 changed files with 17 additions and 15 deletions

View file

@ -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
##

View file

@ -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
##