使用Capistrano重新启动delayed_job

时间:2016-09-06 14:41:17

标签: ruby-on-rails ruby capistrano capistrano3

我正试图像这样重启我的delayed_job工作者:

  task :restart_dj do
    on roles(:app) do
        execute "RAILS_ENV=production #{File.join(current_path,'bin','delayed_job')} restart"
    end
  end

不幸的是,我明白了:

 DEBUG [64a01587] Command: /usr/bin/env ln -s /home/me/rails/dino/releases/20160906142152 /home/me/rails/dino/releases/current
  INFO [64a01587] Finished in 0.177 seconds with exit status 0 (successful).
  INFO [713c695b] Running /usr/bin/env mv /home/me/rails/dino/releases/current /home/me/rails/dino as me@91.16.120.84
 DEBUG [713c695b] Command: /usr/bin/env mv /home/me/rails/dino/releases/current /home/me/rails/dino
  INFO [713c695b] Finished in 0.349 seconds with exit status 0 (successful).
  INFO [7c2e9550] Running RAILS_ENV=production /home/me/rails/dino/current/bin/delayed_job restart as me@91.16.120.84
 DEBUG [7c2e9550] Command: RAILS_ENV=production /home/me/rails/dino/current/bin/delayed_job restart
 DEBUG [7c2e9550]   /home/me/rails/dino/releases/20160906142152/config/boot.rb:1:in `<top (required)>'
 DEBUG [7c2e9550]   :
 DEBUG [7c2e9550]   undefined local variable or method `__dir__' for main:Object
 DEBUG [7c2e9550]    (
 DEBUG [7c2e9550]   NameError
 DEBUG [7c2e9550]   )
 DEBUG [7c2e9550]       from /home/me/rails/dino/releases/20160906142152/config/application.rb:1:in `require_relative'
 DEBUG [7c2e9550]       from /home/me/rails/dino/releases/20160906142152/config/application.rb:1:in `<top (required)>'
 DEBUG [7c2e9550]       from /home/me/rails/dino/current/config/environment.rb:2:in `require_relative'
 DEBUG [7c2e9550]       from /home/me/rails/dino/current/config/environment.rb:2:in `<top (required)>'
 DEBUG [7c2e9550]       from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
 DEBUG [7c2e9550]       from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
 DEBUG [7c2e9550]       from /home/me/rails/dino/current/bin/delayed_job:3:in `<main>'

但是,我可以在我的生产控制台上运行RAILS_ENV=production bin/delayed_job restart,没有任何问题。

我正在使用Ruby 2.3.1。

2 个答案:

答案 0 :(得分:1)

你可以试试https://github.com/AgileConsultingLLC/capistrano3-delayed-job宝石。我个人用它来管理启动,停止和重启。它还处理诸如手动查杀卡住过程等情况。

答案 1 :(得分:0)

错误输出告诉您到底出了什么问题:它不明白__dir__的含义。

undefined local variable or method `__dir__' for main:Object

如果你进一步了解堆栈跟踪,原因很明显:

from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

您正在开发中运行2.3.1,但生产正在使用1.9。如果您在生产中运行多个版本的Ruby,则无法在应用程序代码中正确选择2.3。