【问题标题】:How to specify rvm gemsets for Rails gem whenever?如何在任何时候为 Rails gem 指定 rvm gemsets?
【发布时间】:2013-12-01 07:55:29
【问题描述】:

MyApp 正在使用 rvm gemset 1.9.3@rails-3.2。它不是默认值。

我正在使用 gem 'whenever' 定期发送电子邮件通知。这是我的日程安排。rb:

every 1.minutes do
 runner "MyModel.send_emails" # if ... 
end 

除非 gemset 1.9.3@rails-3.2 是默认值,否则 Cron 作业无法运行。我如何改进我的 schedule.rb 以便为我的调度程序使用其他 gemsets(不仅是默认的@global)。

我已阅读官方文档:wheneverrvm issues 以及关于“rvm gemsets for ever”的 stackoverflow 问题,但没有找到答案。

我尝试将以下代码(根据 RVM-Notes 中的建议)放在我的 shedule.rb 中:

job_type :runner, "{ cd #{@current_path} > /home/####/.rvm/gems/ruby-1.9.3-p448@
rails-3.2/bin/rails; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"

但它没有给出任何结果:

ERROR: 
/home/###/.rvm/gems/ruby-1.9.3-p448@global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92
:in `block in materialize': Could not find i18n-0.6.5 in any of the sources
(Bundler::GemNotFound)

如何为 Rails gem 'whenever' 指定 rvm gemsets?非常感谢!

更新

1) 我尝试为我的 Gemfile 提供 rvm 符号,如下所示:

ruby=ruby-1.9.3-p448 # with # sign

ruby-gemset=rails-3.2 # with # sign

它没有给出任何结果。没有任何变化。

2) 我试图修改我的 ~/.rvmrc。使用捆绑包的完整路径进行实验,rails 给了我以下错误列表:

    /usr/bin/env: ruby: No such file or directory
    /usr/bin/env: ruby: No such file or directory
    /bin/bash: bundle: command not found
    /bin/bash: bundle: command not found
    /usr/bin/env: ruby_executable_hooks/usr/bin/env: ruby_executable_hooks: No such file or directory
   : No such file or directory

这里通过 job_type 实验:

#job_type :runner, "{ cd #{path}; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"
 job_type :runner, "{ cd #{path}; } && RAILS_ENV=:environment /home/###/.rvm/gems/ruby-1.9.3-p448@global/bin/bundle exec rails runner ':task' :output"
#job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/gems/ruby-1.9.3-p448@global/bin/bundle exec /home/###/.rvm/gems/ruby-1.9.3-p448@rails-3.2/bin/rails runner ':task' :output"

【问题讨论】:

  • 你碰巧尝试了 rvmrc 吗??

标签: ruby-on-rails ruby cron rvm whenever


【解决方案1】:

使用包装器:

job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/wrappers/ruby-1.9.3-p448@rails-3.2/bundle exec rails runner ':task' :output"

这将加载正确的 rvm 环境并在其上下文中运行 bundle,bundler 仅添加环境变量以使用来自 Gemfile 的 gem,而无需修改加载的 ruby​​ 环境。

这里描述了类似的情况http://rvm.io/integration/init-d

【讨论】:

  • 谢谢,我的 shedule 日志中没有错误。非常有用的链接
【解决方案2】:

试试

job_type :runner, "cd :path && RAILS_ENV=:environment bundle exec rails runner :task :output"

假设你在Gemfile中提到过

#ruby=ruby-1.9.3-p448
#ruby-gemset=rails-3.2

请参阅RVM Documentation 了解此符号

【讨论】:

  • 我已经这样做了,但是我的日志中有错误:/bin/bash: bundle: command not found。如果我的 gemset 是默认的,一切正常
  • 使用打包器的完整路径
【解决方案3】:

尝试在您的项目根目录中创建 .rvmrc 文件并具有以下行

rvm use 1.9.3@rails-3.2

【讨论】:

  • 我已经尝试过了,但是我的日志中总是有错误消息:/bin/bash: bundle: command not found
  • 如果我评论上述行 job_type :runner,我的日志中出现以下错误:/usr/bin/env: ruby​​: No such file or directory
猜你喜欢
  • 1970-01-01
  • 2012-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多