问题
I added to my app the gems sidekiq
(2.15.0) and sidekiq_mailer
(0.0.6). When I try to send an email, I receive:
NoMethodError (undefined method `key?' for #<JSON::Ext::Generator::State:0x007f1b......
Does anybody have any idea why that is the case?
回答1:
Per this comment on a resque issue I was able to solve a similar issue where I was trying to pass an entire object to the worker's perform
action instead of just the object id. I refactored my code to pass just an id and fetch the necessary objects within the worker themselves.
The deeper issue is that sidekiq only supports native JSON types, so in trying to pass objects to sidekiq it will throw this with anything more complex, say, a ruby object. See this thread for more details and from the docs:
The arguments you pass to perform_async must be composed of simple JSON datatypes: string, integer, float, boolean, null, array and hash. The Sidekiq client API uses JSON.dump to send the data to Redis. The Sidekiq server pulls that JSON data from Redis and uses JSON.load to convert the data back into Ruby types to pass to your perform method. Don't pass symbols or complex Ruby objects (like Date or Time!) as those will not survive the dump/load round trip correctly.
来源:https://stackoverflow.com/questions/19158057/sidekiq-mailer-error-when-trying-to-send-email