我怎样才能在OpenShift上运行我的轨道"何时" / cron任务?

时间:2015-08-19 20:42:58

标签: ruby-on-rails cron openshift whenever

通过随时 gem生成任务时, cron 格式的结果行看起来像这样:

0 13 30 * * /bin/bash -l -c 'cd $OPENSHIFT_REPO_DIR && bin/rails runner -e production "puts \"test\""'

现在,当我通过SSH连接到OpenShift应用程序并尝试执行该bash命令以进行测试时,我收到错误:

# /bin/bash -l -c 'cd $OPENSHIFT_REPO_DIR && bin/rails runner -e production'
/opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- bundler/setup (LoadError)
        from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
        from /var/lib/openshift/$APP_ID/app-root/runtime/repo/config/boot.rb:6:in `<top (required)>'
        from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
        from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
        from bin/rails:9:in `<main>'

如何确保bin/rails runner命令实际执行正确?

1 个答案:

答案 0 :(得分:2)

尝试

/bin/bash -l -c 'cd $OPENSHIFT_REPO_DIR && bundle exec bin/rails runner -e production'

这样在运行命令时它将使用捆绑的宝石。