简体   繁体   English

如何在OpenShift上的“无论何时/执行任务”运行rails?

[英]How can I run my rails “whenever”/cron tasks on OpenShift?

When generating tasks via the whenever gem, the resulting line in cron format looks something like this: 通过everyever gem生成任务cron格式的结果行如下所示:

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

Now, when I SSH into the OpenShift app and try to execute that bash command for testing purposes, I get an error: 现在,当我通过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>'

How can I ensure the bin/rails runner command to actually execute correcty? 如何确保bin/rails runner railsRunner命令能够正确执行?

Try 尝试

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

So that it will use your bundled gems when running the commands. 这样在运行命令时它将使用捆绑的宝石。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM