Skip to content

Workers fail with ruby 2.0 keyword arguments in the perform method #1356

Closed
jeremyhaile opened this Issue Nov 20, 2013 · 13 comments
@jeremyhaile

My worker has a perform method that uses ruby 2.0 keyword arguments:

def perform(user_id: nil, send_notification: false)

This is then called with:

MyWorker.perform_async(user_id: current_user._id, send_notification: true)

Sidekiq shows the following options in the web console: (which is correct)

{"user_id"=>"4f2ab6349d285906d800000a", "send_notification"=>true}

However, the job fails with the following error:

WARN: wrong number of arguments (1 for 0)
WARN:my_worker.rb:3:in `perform'
sidekiq-2.16.1/lib/sidekiq/processor.rb:48:in `block (3 levels) in process'

I've played around with adding an initial argument and also keyword arguments. But that then fails with the same error, but just (2 for 1)

Basically it seems that the Sidekiq introspection code doesn't see the keyword argument at all and fails.

@mperham
Owner
mperham commented Nov 21, 2013

Sidekiq does not support symbols, which keyword args depend on AFAIK. This is because method args must be native JSON types.

@mperham mperham closed this Nov 21, 2013
@anthonyalberto

Any plan to support this? If not possible, could it be added to this page? https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting

Just spent some time trying to google around "sidekiq named parameters" and had a hard time finding this issue!

Thanks!

@mperham
Owner
@anthonyalberto

Perfect, will do

@mbhnyc
mbhnyc commented Sep 17, 2014

:frowing: can't #perform detect keyword args and convert before pushing on the job queue? Keyword args are so nice. Have any experiments been done on this?

@mperham
Owner
@aprescott

To my knowledge, the most you can get is Method#parameters:

>> def foo(a, b=1, c: 2, d:, **z); end
=> :foo
>> method(:foo).parameters
=> [[:req, :a], [:opt, :b], [:keyreq, :d], [:key, :c], [:keyrest, :z]]

No conversion could happen before putting the job on the queue, though, because that's when serialization will convert it to JSON. You'd have to convert just before calling perform. (sidekiq-symbols is a gem that enables this functionality for a worker.)

@yazinsai

+1

@amacneil

👍

This issue shouldn't be closed (or at the very least, sidekiq should return a more useful error message stating that keyword arguments are not supported when it detects them).

@bshyong
bshyong commented Mar 5, 2015

+1

@camallen camallen added a commit to camallen/Panoptes that referenced this issue Apr 27, 2015
@camallen camallen remove keywork syntax from sidekiq workers
sidekiq doesn't support workers with keyword args, mperham/sidekiq#1356
132f206
@camallen camallen referenced this issue in zooniverse/Panoptes Apr 27, 2015
Merged

remove keywork syntax from sidekiq workers #749

@kpascascio

+1

@jekuta
jekuta commented Mar 11, 2016

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.