R
R
rutaka nashimo2015-06-17 11:33:32
ruby
rutaka nashimo, 2015-06-17 11:33:32

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

1 answer(s)
_
_ _, 2015-06-17
@rutaka_n

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 question

Ask a Question

731 491 924 answers to any question