whenever gem not working, Rails 4

941 views Asked by At

I am using Whenever gem to schedule some work on my site. Currently I am working on development environment.

I have instaled gem as guide suggests.

In schedule.rb

 every 2.minutes do

  rake "vip_recomend:give"
 end

In lib/tasks/vip_recomend.rake

   namespace :vip_recomend do
      desc "Give vip recomend to ads that are in waiting list"

      task give: :environment do

        girls = Girl.all
           girls.each do |girl|               
               BlacklistMailer.blacklisted(girl).deliver                    
           end  

           user = User.first
            UserMailer.password_reset(user).deliver

      end   
    end

Then I tried these comands:

whenever --set environment=development --update-crontab

or

whenever --update-crontab

Nothing happens.

Then I check if cron is updated with my stuff with this:

crontab -l

Output:

# Begin Whenever generated tasks for: /home/my_host/blogs/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/my_host/blogs && RAILS_ENV=development bundle exec rake vip_recomend:give --silent >> /log/cron_log.log 2>&1'

# End Whenever generated tasks for: /home/my_host/blogs/config/schedule.rb

When I try to run rake task from console it works.

Any help on this? Thanks.

Update 1

when in schedule.rb I have this

env :PATH, ENV['PATH']

In cron error logs I get this message.

/opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/dependency.rb:298:in `to_specs': Could not find 'bundler' (>= 0) among 8 total gem(s) (Gem::LoadError)
    from /opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/dependency.rb:309:in `to_spec'
    from /opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/core_ext/kernel_gem.rb:53:in `gem'
    from /home/individualki/rubyvenv/ror/2.1/bin/bundle:22:in `<main>'
3

There are 3 answers

0
Edgars On BEST ANSWER

SOLUTION:

I changed Whenever to Rufus-scheduler.

Before that I tried EVERY possible solution to fix my problem. I think problem was in my Ruby installation on shared hosting, but I didn't have time to examine it.

2
MarsAtomic On

Try writing your jobs in schedule.rb in the following format, with a specified environment:

every 2.minutes do
  rake "vip_recomend:give", :environment => 'development'
end

Then go to your command prompt, and from within your application directory, try the following:

$ whenever --update-crontab
$ whenever

You should see that whenever lists your tasks with ENV=DEVELOPMENT now.

4
Rokibul Hasan On

PATH problem may be, by putting the following at the top of the schedule.rb, ensure correct bundle path

env :PATH, ENV['PATH']

Or try to add following if above one not work.

env :GEM_PATH, ENV['GEM_PATH']