문제

Within my controller action i am using render_to_string with a jbuilder template to render an object for a http post action to an API, the results of this API-Call is what should be rendered by the controller.

But i get a strange timeout then i call HTTParty after i rendered the model via render_to_string.

Log:

[23:43:52.262] [18033] [info]   Rendered admin/companies/companies.json.jbuilder (42.8ms)
... nothing happens here (60s timeout)
[23:44:52.314] [18033] [info] Completed 500 Internal Server Error in 60338ms
[23:44:52.342] [18033] [fatal] 
Timeout::Error (Timeout::Error):
  app/controllers/admin/companies_controller.rb:135:in `copy_to_environment'
  lib/middleware/x_domain_request_polyfill.rb:46:in `_call'
  lib/middleware/x_domain_request_polyfill.rb:16:in `call'
[23:44:52.422] [18033] [info] Started POST "/api/v1/internal/company/create_company_copy.json" for 127.0.0.1 at 2013-05-26 23:44:52 +0200
[23:44:52.465] [18033] [info] Processing by Api::V1::Internal::CompaniesController#create_company_copy as JSON
[23:44:52.465] [18033] [info] User Agent: 
[23:44:52.466] [18033] [info] Completed 200 OK in 1ms (Views: 0.2ms | Models: 0.0ms)
[23:44:52.466] [18033] [info] Response is {"status":"success"}

Controller-Action:

json_string = render_to_string(:template => '/admin/companies/companies', :formats => [:json],locals: { company: @company })
api_action = "/api/v1/internal/company/create_company_copy.json"
urlstring_to_post = 'http://localhost:3000'+ api_action
@result = HTTParty.post(urlstring_to_post.to_str, :body => JSON.parse(json_string))
render(:show, :formats => [:html])

The strange thing for me is as you can see in the log that the actual controller action fails because of the timeout and thus the errorpage is rendered to the user, BUT the post to the API is successfully executed but only right after the timeout.

Any suggestions appreciated!

도움이 되었습니까?

해결책

Common problem, but hard to track if too close to monitor.

I guess you run rails server which normally starts one single WEBrick server process.

Unfortunately you will block yourself while local testing.

Fix: Start another rails server with different port number. Or start something like unicorn and set worker number to 2 or more.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top