0

I am trying to get whenever to run my rake task but it doesn't work.

#Command Line
$ whenever -w
[write] crontab file written


#schedule.rb
every :year, :at => "2014-07-25 17:39:48 -0700" do
  rake 'timeperiod:create_timeperiod'
end

The rake command saves a model in the db and puts text so I would know if it worked (which it does when I run rake). Is there syntactically something wrong with what I did?

Note, the time and date in schedule.rb is arbitrary, I keep changing it to two minutes from now before testing.

Eric Baldwin
  • 3,341
  • 10
  • 31
  • 71

4 Answers4

1

Your task is probably failing because the shell used by cron is not the same you use with your normal user.

Check the log of the crontab:

grep CRON  /var/log/syslog
sites
  • 21,417
  • 17
  • 87
  • 146
0

Why don't you verify that your command is getting added to the crontab?

$ crontab -l

You can also add the job manually.

$ whenever
* * * * * * bash -l 'cd /path/to/dir; rake your:task'

$ crontab -e
# add the cron job

Also, output from cron jobs doesn't output to the screen; it goes to your mail. Check your mailbox.

From the man page:

When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output.

mz3
  • 1,314
  • 11
  • 27
0

For me, I'm using command but I think it's not the best case. Says my repo is in $HOME/www/virtualspirit, in my repository. So my whenever command will be cd /www/virtualspirit && /$HOME/.rvm/rubies/ruby-2.1.2/bin/rake timeperiod:create_timeperiod RAILS_ENV=production

double check it in crontab -e and see whether it saved.

Nich
  • 1,112
  • 1
  • 14
  • 29
  • My output after `crontab -e` is in this pastie: http://pastie.org/9423365 Suffice it to say, the command was saved. – Eric Baldwin Jul 26 '14 at 21:13
  • @EricBaldwin is this development or production? your pastie show it using development, and the command generated i think it in correct, from the command you show me, you can just try to execute it in your $HOME path with cd ~ && RAILS_ENV=development bundle exec rake timeperiod:create_timeperiod --silent – Nich Jul 27 '14 at 14:02
  • I think it will not execute your task...try it and see – Nich Jul 27 '14 at 14:02
  • It is in development. I found an answer, I just can't accept it for 15 hours because of Stack Overflow's structure – Eric Baldwin Jul 27 '14 at 14:03
-1

There were a couple issues here.

  1. The best way to add cron jobs to whenever is with the command whenever --update-crontab <name of identifier>
  2. The format was incorrect. By specifying the time in cron directly, I was able to make it work.

For example:

#schedule.rb
every '13 15 26 7 *' do
  rake 'timeperiod:create_timeperiod'
end
Eric Baldwin
  • 3,341
  • 10
  • 31
  • 71