问题
MyApp is using rvm gemset 1.9.3@rails-3.2. It is not default.
I am using gem 'whenever' to periodically send email notifications. This is my schedule.rb:
every 1.minutes do
runner "MyModel.send_emails" # if ...
end
Cron job is not working unless gemset 1.9.3@rails-3.2 is default. How can i improve my schedule.rb in order to use another gemsets (not only default @global) for my scheduller.
I have read official documentation: whenever and rvm issues and stackoverflow questions about "rvm gemsets for whenever", but have not found an answer.
I have tried to put the following code (according to advice in RVM-Notes) in my 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"
but it gives no result:
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)
How to specify rvm gemsets for Rails gem 'whenever'? Many thanks!
UPDATE
1) I have tried to provide rvm notaions for my Gemfile like this:
ruby=ruby-1.9.3-p448 # with # sign
ruby-gemset=rails-3.2 # with # sign
It gives no result. Nothing changes.
2) I have tried to modify my ~/.rvmrc. Experiments with full path to bundle, rails gives me the following list of errors:
/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
Here by job_type experiments:
#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"
回答1:
use wrapper:
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"
this will load proper rvm environment and run bundle
in its context, bundler only adds environment variables for using gems from Gemfile
without modifying the loaded ruby environment.
a similar situation is described here http://rvm.io/integration/init-d
回答2:
try
job_type :runner, "cd :path && RAILS_ENV=:environment bundle exec rails runner :task :output"
Assuming you have mentioned in Gemfile
#ruby=ruby-1.9.3-p448
#ruby-gemset=rails-3.2
See RVM Documentation for this notation
回答3:
Try to create .rvmrc file in your project root directory and have the following line
rvm use 1.9.3@rails-3.2
来源:https://stackoverflow.com/questions/20043161/how-to-specify-rvm-gemsets-for-rails-gem-whenever