簡體   English   中英

Strange Timeout :: Controller Action中的render_to_string和HTTParty出錯

[英]Strange Timeout::Error with render_to_string and HTTParty in Controller Action

在我的控制器操作中,我使用帶有jbuilder模板的render_to_string來向API呈現http post操作的對象,此API-Call的結果應該由控制器呈現。

但是我得到一個奇怪的超時然后我通過render_to_string渲染模型后調用HTTParty。

日志:

[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"}

控制器操作:

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])

對我來說奇怪的是,你可以在日志中看到實際的控制器操作由於超時而失敗,因此錯誤被呈現給用戶,但是發布到API的帖子成功執行但僅在超時之后。

任何建議贊賞!

常見問題,但如果太靠近監視器則難以跟蹤。

我猜你運行的rails server通常會啟動一個WEBrick服務器進程。

不幸的是,你會在本地測試時阻止自己。

修復:啟動另一個具有不同端口號的rails服務器。 或者啟動類似獨角獸的東西,並將工人數量設置為2或更多。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM