Threading in Rails - execute [] persist parameters?

I am trying to create a thread in Rails. I am usually not comfortable using streams, as I will need to have a deep knowledge of the Rails request / response cycle, but I cannot avoid using it as a temporary request.

To avoid a timeout, I use a stream in the request. My question here is simple. The thread I used accesses the params [] variable inside it. And now everything is working fine. I want to know if this is correct? I would be happy if someone could shed some light on the use of threads in Rails during a request / response cycle.

[Bonus launch]

+3
source share
2 answers

- , ; , , . , ( Rails) params. . ( "" Ruby), , , ( ), . , , , . - - : .

Rails , ​​: http://gist.github.com/637719. , - 5.

. - Thread.new, :

# always dup objects when passing into a thread, else you really
# haven't done yourself any good-it would still be the same memory
Thread.new(params.dup) do |params|
  puts params[:foo]
end

, , . , , , . , .

, , , . , Ruby, , Rails. , Ruby, , , . , , ; "" . , Resque, Delayed Job , Rails, .

+5

, , , .

, , , . , .

, ( , ), , , .

+1

Source: https://habr.com/ru/post/1768578/


All Articles