Mihail Davydenkov
Mihail Davydenkov

Reputation: 1861

How to specify rvm gemsets for Rails gem whenever?

MyApp is using rvm gemset [email protected]. 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 [email protected] 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/[email protected]/bin/rails runner ':task' :output"

Upvotes: 0

Views: 2478

Answers (3)

mpapis
mpapis

Reputation: 53158

use wrapper:

job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/wrappers/[email protected]/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

Upvotes: 3

Litmus
Litmus

Reputation: 10996

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

Upvotes: 1

yednamus
yednamus

Reputation: 583

Try to create .rvmrc file in your project root directory and have the following line

rvm use [email protected]

Upvotes: 0

Related Questions