Reputation: 2410
After setting up sidekiq, I observed a strange behavior with respect to the arguments passed to the Sidekiq::Client.push
method
If I give self.class
as args, then I either get a SystemStackError (stack level too deep)
OR the server simply hung up, thereafter accepting no request.
Sidekiq::Client.enqueue(ActivityWorker, self.id, self.class)
SystemStackError (stack level too deep):
actionpack (3.2.12) lib/action_dispatch/middleware/reloader.rb:70
Rendered /usr/local/rvm/gems/ruby-1.9.3-p194@restro/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p194@restro/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.0ms)
Rendered /usr/local/rvm/gems/ruby-1.9.3-p194@restro/gems/actionpack-3.2.12/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (37.8ms)
But if I give self.class.name
then it works without any flaw.
Sidekiq::Client.enqueue(ActivityWorker, self.id, self.class.name)
I found that the args are serialized before they are passed to the worker, but am unable to figure out this scenario.
Here's my Worker class
class ActivityWorker
include Sidekiq::Worker
sidekiq_options queue: 'high', retry: false
def perform(res_id, res_class)
# do some activity
end
end
Upvotes: 2
Views: 1200
Reputation: 4245
You shouldn't enqueue job with arguments like class object. It should be simple types, for example strings, numbers, hashes and arrays of them.
For the most of classes, except the spedical ones which I mentioned and probably some other, Sidekiq serialize this parameter to redis just as empty hash. So it's no way to deserialize from it back to your class.
I suggest you to pass self.class.name
to the enqueue
method as you tried, and then use constantize
to get a class from string.
Upvotes: 3