0

I am using whenever gem to write a simple cron job like.

every 1.minute do 
  runner "ValidModel.clean"
end

I see that this cron fires at the right time but the Rails command ValidModel.clean doesn't succeed. It gives the following error:

/home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:271:in `find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException)
        from /home/deploy/.rvm/rubies/ruby-2.4.2/lib/ruby/site_ruby/2.4.0/rubygems.rb:299:in `activate_bin_path'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/bundle:23:in `<main>'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `eval'
        from /home/deploy/.rvm/gems/ruby-2.4.2/bin/ruby_executable_hooks:15:in `<main>'

I am using RVM. Is this issue related with using RVM with whenever?

Update

In gemfile I have put

gem 'whenever', require: false

When I run crontab -l it lists the following:

PATH=/home/deploy/apps/app/shared/bundle/ruby/2.4.0/bin:/home/deploy/.rvm/gems/ruby-2.4.2/bin:/home/deploy/.rvm/gems/ruby-2.4.2@global/bin:/home/deploy/.rvm/rubies/ruby-2.4.2/bin:/home/deploy/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
GEM_PATH=""

* * * * * /bin/bash -l -c 'cd /home/deploy/apps/app/releases/20180121061036 && bundle exec bin/rails runner -e production '\''ValidModel.clean'\'' >> /home/deploy/apps/app/releases/20180121061036/log/cron.log 2>&1'

What can I try next?

halfer
  • 19,824
  • 17
  • 99
  • 186
kofhearts
  • 3,607
  • 8
  • 46
  • 79
  • 1
    Look at the output of `rvm gemset list`, then `gem list`. Do you see the `whenever` gem? Actually, do you see the `bundler` gem? – 7stud Jan 21 '18 at 06:55
  • ok i just ran gem list and i dont see whenever gem listed there. In my gemfile i have put require => false for whenever. – kofhearts Jan 21 '18 at 07:01
  • 1
    https://stackoverflow.com/questions/20043161/how-to-specify-rvm-gemsets-for-rails-gem-whenever – 7stud Jan 21 '18 at 07:55
  • ok it is working all of a sudden. my guess is the code to execute was throwing exception. I ran simple code like puts "hello", it runs properly. – kofhearts Jan 21 '18 at 07:58

0 Answers0