5

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 
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • it is not running the cron job in every minute. which mistake i have done in that? how can i run that for every minute? – Nirav Acharya Apr 06 '13 at 05:47
  • 1
    Hi Nirav, i have gone through your question and according to my view the cron job must be working but there is some error in logic, can you please post the error code from '/log/error.log' file... – Jeet Apr 15 '13 at 08:57
  • Hi Jeet, it isn't creates even log files for cronjobs. is that any specific reasons? error i already mention. if i run whenever, it not run perfectly. see the last line of main post. – Nirav Acharya Apr 15 '13 at 09:23
  • I also check for it is running in server or not but it not runs in server. simply i want that cronjob run for every minute/hour/day. it is for mail scheduler. – Nirav Acharya Apr 15 '13 at 09:25
  • Is that any other way i have to go through for this solution? – Nirav Acharya Apr 15 '13 at 09:26
  • 2
    Nirav take a look at this two links i.e. https://github.com/javan/whenever#define-your-own-job-types and https://github.com/javan/whenever/wiki/Output-redirection-aka-logging-your-cron-jobs, and see your point at first 2 lines after command 'localhost:~/project$ crontab -l', which says that cron jobs are running but there may be some mistake(i may be wrong also, its a guess only) in 'runner "User.weekly_update"' line in your schedule.rb file... – Jeet Apr 15 '13 at 09:45
  • 1
    one more thing in your model the method name should be like "def self.weekly_update", so dont forget it – Jeet Apr 15 '13 at 09:49
  • 1
    Hi Jeet, thanx buddy but I have def self.weekly_update in User model. and for runner "user.weekly_update" i used reference of cronjob in github as i mention in first line – Nirav Acharya Apr 15 '13 at 09:57
  • 1
    I have already gone through your link. Thanx Jeet – Nirav Acharya Apr 15 '13 at 10:00
  • Hi jeet, i have added method that i have written in User model. see it and tell me if any thing wrong with it? – Nirav Acharya Apr 15 '13 at 10:05
  • 1
    Nirav can you set output to '/var/log/error.log' and /var/log/cron.log..., I am not sure about it – Jeet Apr 15 '13 at 10:11
  • 1
    And can you try with this in console 'script/rails runner -e production "User.weekly_update"', if it gives result then there should not be any issue – Jeet Apr 15 '13 at 10:13
  • OK for log it is not created for cronjob. and for commend you suggest i will check it out and tell you. thanx – Nirav Acharya Apr 15 '13 at 10:22
  • 1
    May be log are not reflecting because you have given wrong path, try with whole path(take it as random guess) – Jeet Apr 15 '13 at 10:25
  • Thanx Jeet but it was some thing small click is needed it was not working in production also. by the way we will discuss this later and make a small demo of it. so we can understand better. thanx for your advice but we need to more work on it to understand it very well. and one more thing, in cronjob many more methods are there like runner(model ad definition), rake task , Capistrano etc... right there are different method. can i have to go for another methods for it. what is your suggestion? Thanx – Nirav Acharya Apr 15 '13 at 10:40
  • 1
    No problem dude, it should work with runner also, so that is not an issue, i will take close look on your code and get back to you as earlier as possible – Jeet Apr 15 '13 at 10:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28236/discussion-between-nirav-acharya-and-jeet) – Nirav Acharya Apr 15 '13 at 10:56

1 Answers1

1

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 :)

Manoj Sehrawat
  • 1,283
  • 1
  • 10
  • 25