Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run cronjob using whenever in rails 3

i follow all the steps for whenever with reference to https://github.com/javan/whenever

in schedule.rb

require 'yaml'
set :environment, 'production'
set :output, {
    :error    => "/log/error.log",
    :standard => "/log/cron.log" 
}

every 1.minute do
   runner "User.weekly_update"
end

in gemfile

gem 'whenever', :require => false

output of some command

localhost:~/project$ whenever -i

[write] crontab file updated

localhost:~/project$ crontab -l

# Begin Whenever generated tasks for: /home/bacancy/project/config/schedule.rb
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e     production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'

# End Whenever generated tasks for: /home/bacancy/project/config/schedule.rb

# Begin Whenever generated tasks for: store
* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e  development '\''User.weekly_update'\'''

# End Whenever generated tasks for: store

# Begin Whenever generated tasks for: lapulguilla

# End Whenever generated tasks for: lapulguilla

and then i type

localhost:~/project$ whenever

* * * * * /bin/bash -l -c 'cd /home/bacancy/project && script/rails runner -e    production '\''User.weekly_update'\'' >> /log/cron.log 2>> /log/error.log'

## [message] Above is your schedule file converted to cron syntax; your crontab file  was not updated.
## [message] Run `whenever --help' for more options.

In User model i have definition self.weekly_update

def self.weekly_update
  puts "cronjobs is called in every minutes"
end 
like image 252
Nirav Acharya Avatar asked Nov 12 '22 08:11

Nirav Acharya


1 Answers

Your everything is correct, its just that you are saying to cron job to print something in background, so it is doing that and you are able to observe it.

Instead you should try create or destroy some records to feel the changes i think :)

like image 147
Manoj Sehrawat Avatar answered Nov 14 '22 22:11

Manoj Sehrawat