我如何在 OpenShift 上 运行 我的 rails "whenever"/cron 任务?

How can I run my rails "whenever"/cron tasks on 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命令正确执行?

尝试

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

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