使用bundle exec运行延迟的作业

时间:2019-07-17 07:03:35

标签: ruby-on-rails ruby ruby-on-rails-4 rubygems delayed-job

一般来说,我将使用cmd开始delay_job:

RAILS_ENV=production bin/delayed_job start

现在,我编写了一个简单的启动脚本,以在重新启动后自动启动延迟的作业。

我发现,如果我在脚本中编写了上面的cmd,它将失败。

# this is the execution in the upstart conf
exec RAILS_ENV=production bin/delayed_job start

经过一番谷歌测试之后,我发现这可以在我的脚本中运行:

 exec bundle exec /usr/bin/env RAILS_ENV=production bin/delayed_job start

这导致了我的问题,我猜/usr/bin/env RAILS_ENV=production是将环境变量传递到bin / delay_job脚本中,捆绑执行在这里如何?

脚本中没有bundle exec,它将引发与

有关的错误

require': cannot load such file -- bundler/setup (LoadError)

我意识到使用bundle exec可以在某些环境下运行rails,但是为什么在脚本中有此必要呢? 还是我想在脚本中执行bundle execbin/delayed_job之类的cmd时需要rake吗?

谢谢。

已更新

我将upstart脚本复制到另一个节点并以相同的方式执行它。 但是,它引发了不兼容的库版本错误... 我跑

 bundle exec /usr/bin/env RAILS_ENV=production bin/delayed_job start

直接在终端上运行,并且按预期方式工作,但是将上述命令放在脚本中失败。

有人可以告诉我为什么执行相同命令但在不同位置时结果不同吗?

0 个答案:

没有答案