3

I have setup my schedule.rb file as follows.

set :cron_log, "/log/cron_log.log"
if Rails.env.development?
  every 1.minute do
    runner "SomeModel.move_values"
    runner "SomeOtherModel.dispense"
   end
end

I also make it work in development mode by whenever --update-crontab trunk --set environment=development

But my model methods (class methods) are never called. Is there some way I can verify if its configured right. when I simply use update it resets the settings to use the production environment.

Sid
  • 6,134
  • 9
  • 34
  • 57

2 Answers2

2

I just got done using that same javan-whenever plugin.

In terminal, type crontab -l. If you see the crontab properly generated then you know it's either the code or some server thing.

You may want to consider doing set :environment, RAILS_ENV in your schedule.rb file to set the environment dynamically.

Ryan Bates has done a good screencast on this: http://railscasts.com/episodes/164-cron-in-ruby

Also, there are web-based alternatives, for example: webbasedcron

tybro0103
  • 48,327
  • 33
  • 144
  • 170
  • Hey thanks for the answer but I started off after going through the screencasts and the crontab -l does display * * * * * /home/sid/folder/trunk/script/runner -e production "CreditDetail.move_values" >> /log/cron.log 2>&1 * * * * * /home/sid/folder/trunk/script/runner -e production "Exp.dispense" >> /log/cron.log 2>&1 but it does not update my log or the run the cron. Im not sure if I am missing something or have my configurations gone wrong somewhere I will checkout the link you sent me but I would still appreciate some help on this – Sid Nov 11 '09 at 15:25
  • Just to be sure, the crontab you just posted is from your production server correct? If not, it should say "-e development". Another check, if you open the console and run "CreditDetail.move_values" or "Exp.dispense" are any errors thrown? – tybro0103 Nov 11 '09 at 16:29
  • No i want to run the cron on my development machine. And thanks for the answer. I realized that the version of the gem i was using was dated and the one available on gemcutter is the newest version of the gem. I got it running once i got the gem from the new source. Thank you. – Sid Nov 12 '09 at 11:12
  • oh cool.. just be sure to set the environment to dev since it defaults to production.. :) – tybro0103 Nov 12 '09 at 14:38
1

Run whenever --set environment=test -w

to create your crontab on a test environment, obviously you can replace test with whatever environment you are running on.

KKK
  • 1,085
  • 11
  • 33