sidekiq_mailer error when trying to send email

孤街浪徒 提交于 2019-12-12 21:33:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!