2013-05-02 107 views
0

我正在編寫一個使用Open3調用perl腳本的Ruby on Rails應用程序。但是,當調用perl腳本時,我的應用程序不斷提高Timeout :: Error比我想要的更快。在那裏我調用腳本的代碼如下所示:Ruby on Rails調用perl腳本超時

Timeout::timeout(120){ 
     @stdout, @stderr, @exit_code = Open3.capture3(@command) 
     [@exit_code.to_i, @stdout, @stderr] 
    } 

我實現調用一個潛在的「長」行書(也許20-30秒TOPS)是不理想的on Rails應用程序紅寶石,但我不沒有太多的選擇。

我正在使用獨角獸來獲得併發性,並將獨角獸超時設置爲60秒。儘管我的獨角獸文件出現了60秒的超時時間,並且圍繞Open3調用的120秒超時,我的請求仍然保持在18秒左右的時間。我知道腳本已經成功完成了,因爲我看到了另一側的結果,但我需要我的應用程序來等待腳本的返回。

有沒有其他辦法可以強制我的Rails應用程序等待,而不是超時?

謝謝!從陷入錯誤

回溯:

 
execution expired 
/opt/sen/ruby/lib/ruby/1.9.1/open3.rb:280:in `value' 
/opt/sen/ruby/lib/ruby/1.9.1/open3.rb:280:in `block in capture3' 
/opt/sen/ruby/lib/ruby/1.9.1/open3.rb:208:in `popen_run' 
/opt/sen/ruby/lib/ruby/1.9.1/open3.rb:90:in `popen3' 
/opt/sen/ruby/lib/ruby/1.9.1/open3.rb:270:in `capture3' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/models/perl_exec.rb:23:in `block in execute' 
/opt/sen/ruby/lib/ruby/1.9.1/timeout.rb:68:in `timeout' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/models/perl_exec.rb:22:in `execute' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/models/reservoir.rb:47:in `execute!' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/models/reservation.rb:93:in `commit!' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/controllers/reservations_controller.rb:106:in `block in commit' 
/opt/sen/ruby/lib/ruby/1.9.1/timeout.rb:68:in `timeout' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/controllers/reservations_controller.rb:105:in `commit' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/implicit_render.rb:4:in `send_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/base.rb:167:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/rendering.rb:10:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/callbacks.rb:18:in `block in process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:469:in `_run__3753465240598785610__process_action__3320622668841691210__callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/callbacks.rb:17:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/rescue.rb:29:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/notifications.rb:123:in `block in instrument' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/notifications/instrumenter.rb:20:in `instrument' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/notifications.rb:123:in `instrument' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/instrumentation.rb:29:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/params_wrapper.rb:207:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/railties/controller_runtime.rb:18:in `process_action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/base.rb:121:in `process' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/rendering.rb:45:in `process' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal.rb:203:in `dispatch' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_controller/metal.rb:246:in `block in action' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:73:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:73:in `dispatch' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:36:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `each' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/journey-1.0.4/lib/journey/router.rb:56:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:601:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-timeout-0.0.3/lib/rack/timeout.rb:16:in `block in call' 
/opt/sen/ruby/lib/ruby/1.9.1/timeout.rb:68:in `timeout' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-timeout-0.0.3/lib/rack/timeout.rb:16:in `call' 
/opt/sen/bpt/releases/aa47354a897077a6600349fd6c473704bb17f929/app/middleware/nestful.rb:18:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/etag.rb:23:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/conditionalget.rb:35:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/head.rb:14:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/flash.rb:242:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/cookies.rb:341:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/query_cache.rb:64:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.2.9/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `_run__4121137639594084607__call__1985817909290506524__callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:405:in `__run_callback' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:385:in `_run_call_callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/callbacks.rb:81:in `run_callbacks' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/remote_ip.rb:31:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:32:in `call_app' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `block in call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/tagged_logging.rb:22:in `tagged' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/rack/logger.rb:16:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/request_id.rb:22:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/runtime.rb:17:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.2.9/lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-1.4.1/lib/rack/lock.rb:15:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/middleware/static.rb:62:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:136:in `forward' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:143:in `pass' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:155:in `invalidate' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:71:in `call!' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-cache-1.2/lib/rack/cache/context.rb:51:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:479:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:223:in `call' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:552:in `process_client' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:632:in `worker_loop' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:142:in `start' 
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/unicorn-4.6.2/bin/unicorn_rails:209:in `' 
/opt/sen/ruby/bin/unicorn_rails:23:in `load' 
/opt/sen/ruby/bin/unicorn_rails:23:in `' 
+0

您的腳本如何超時?獨角獸超時 - 殺死你的應用程序還是超時模塊做到這一點? – Hongli 2013-05-05 18:20:18

+0

我不確定是什麼導致超時。它不應該是獨角獸超時或超時塊。當用戶點擊啓動動作的按鈕時,請求在大約18-20秒後超時。這是在60年代的獨角獸超時和120秒的超時模塊之前。如果請求本身沒有從服務器回聽太久,請求本身是否會計時? – Chris 2013-05-06 18:35:56

+0

我不知道沒有更多的細節。你應該提供一個堆棧跟蹤或其他東西。 – Hongli 2013-05-06 18:56:15

回答

1

正如你可以在堆棧跟蹤

/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/rack-timeout-0.0.3/lib/rack/timeout.rb:16:in `call' 

你有Rack中間件(機架超時)看到,在強制的額外超時完整的請求。配置或刪除該中間件,你應該沒問題。

+0

謝謝!這就是訣竅! – Chris 2013-05-08 21:54:11