0

我正在编写一个使用 Open3 调用 perl 脚本的 Ruby on Rails 应用程序。但是,当调用 perl 脚本时,我的应用程序会比我想要的更快地引发 Timeout::Error。我调用脚本的代码如下所示:

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

我意识到调用一个潜在的“长时间”运行脚本(可能是 20-30 秒)对于 ruby​​ on rails 应用程序来说并不理想,但我没有太多选择。

我正在使用独角兽来获得并发性,并且我将独角兽超时设置为 60 秒。尽管我的 unicorn 文件中有 60 秒超时,并且 Open3 调用周围有 120 秒超时,但我的请求仍然在 18 秒左右超时。我知道脚本已成功完成,因为我在另一边看到了结果,但我需要我的应用程序等待脚本返回。

有没有其他方法可以强制我的 Rails 应用程序等待而不是超时?

谢谢!

从捕获的错误回溯:

执行期满
/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 `执行!
/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/instrument.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:在“进程”中
/opt/sen/ruby/lib/ruby/gems/1.9.1/gems/actionpack-3.2.9/lib/abstract_controller/rendering.rb:45:在“进程”中
/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 `'
4

1 回答 1

1

正如您在堆栈跟踪中看到的

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

你有一个 Rack 中间件(rack-timeout),它会在整个请求上强制额外超时。配置或删除该中间件,你应该没问题。

于 2013-05-08T21:05:37.217 回答