mercredi 4 décembre 2019

Accessing Module inside a Thread Ruby

I have a Service which calls a method that runs inside thread. But the code inside thread has access to other module methods. The thread is getting struck when the module method is called.

Service:

  def place_order
    threads = []
    @responses = []
    order_params.each_with_index do |order, index|
      threads << Thread.new do
        @responses << Module1::Class1.place_order(order)
      end
   end
   threads.each &:join
  @responses
end

Module1::Class1's place_order method:

def place_order(options)
  order_params = { body: order_config(options).to_json }
  resp = make_request(:post, "/v3/order/", order_params).parsed_response
  Rails.logger.info "QWIK_CILVER::ORDERResponse:: #{resp.inspect}"
  ***The below code calls a method in different module which is not running******     
  Module2::SubModule1::Class1.parse(resp, self)
end

THe server is hanged and I am not even able to stop the server after that. Have to kill the process manually and start the server again. How can I call the Module2::SubModule1::Class1's method inside thread?

Aucun commentaire:

Enregistrer un commentaire