0

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>'
Edgars
  • 913
  • 1
  • 19
  • 53

3 Answers3

3

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.

MarsAtomic
  • 10,436
  • 5
  • 35
  • 56
1

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']
Rokibul Hasan
  • 4,078
  • 2
  • 19
  • 30
  • thanks but still some issues. Also updated my question with some error messages. – Edgars Jun 15 '15 at 18:18
  • When I want to use rails commands using SSH, then I have to execute this command ' source rubyvenv/ror/2.1/bin/activate' – Edgars Jun 15 '15 at 18:29
  • Seem bundle gem not found, try with `gem install bundler` and read form [here](http://stackoverflow.com/questions/6166081/could-not-find-bundler-error) – Rokibul Hasan Jun 15 '15 at 18:33
  • Thanks but I have installed bundler . gem list bundler returns bundler (1.8.2) – Edgars Jun 16 '15 at 17:57
1

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.

Edgars
  • 913
  • 1
  • 19
  • 53