Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
jeremyhaile opened this Issue · 10 comments

8 participants

@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

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

: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.)

@adrianmacneil

:+1:

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

+1

@camallen camallen referenced this issue from a commit in camallen/Panoptes
@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
Merged

remove keywork syntax from sidekiq workers #749

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.