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.
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!
Thanks!
Good idea. You can edit the wiki and add it yourself.
On Tue, May 20, 2014 at 6:37 AM, Anthony Alberto
[email protected]:
Any plan to support this? If not possible, could it be added to this page?
https://github.com/mperham/sidekiq/wiki/Problems-and-TroubleshootingJust spent some time trying to google around "sidekiq named parameters"
and had a hard time finding this issue!Thanks!
—
Reply to this email directly or view it on GitHubhttps://github.com/mperham/sidekiq/issues/1356#issuecomment-43626021
.
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?
Not that I know of, care to do some research?
On Sep 16, 2014, at 19:53, Matthew Hensrud [email protected] wrote:
: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?
—
Reply to this email directly or view it on GitHub.
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.)
:+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).
Most helpful comment
:+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).