Answer the question
In order to leave comments, you need to log in
Why in ruby is an object converted to a string when passed to a method?
I'm using resque 1.25.* in a Sinatra application and it becomes necessary to pass the Sinatra(settings) application object to resque-job, but for some reason, when passed to the job'a perform method, the object is converted to a string. Has anyone experienced something similar? and why is this happening?
example:
p settings.class #=> Class
Resque.enqueue(JobClass, settings)
#In JobClass
def perform(settings)
p settings.class #=> String
end
Answer the question
In order to leave comments, you need to log in
Because the intermediate storage, which is resque, which is sidekiq, stores data in the form of strings, most often in redis. Therefore, forget about passing objects like Class (this, by the way, is written in the documentation).
With a well-designed application, there is no need to pass complex objects to workers. Apparently, you incorrectly integrated resque into the project - the settings can be passed to the worker when resque starts.
Inside the library, the json format is used to store call parameters, in my opinion, therefore, objects with .to_json can be used as worker parameters
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question