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)
However, the job fails with the following error:
WARN: wrong number of arguments (1 for 0)
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.
Pick your reaction
Sidekiq does not support symbols, which keyword args depend on AFAIK. This is because method args must be native JSON types.
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!
Perfect, will do
: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?
To my knowledge, the most you can get is Method#parameters:
>> def foo(a, b=1, c: 2, d:, **z); end
=> [[: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.)
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).
remove keywork syntax from sidekiq workers
sidekiq doesn't support workers with keyword args, mperham/sidekiq#1356