I did the following to implement cron jobs in rails 3 using a “runner” instead of a rake task.
Step 1: I have whenever gem installed and scheduler.rb has following:
set :environment, 'development'
set :output, {
:error => "/log/error.log",
:standard => "/log/cron.log"
}
every 1.minute do
runner "Cron.sendAutomaticsSMS()"
end
Step 2:
Cron file: lib/cron.rb
class Cron < ActiveRecord::Base
def **sendAutomaticsSMS**()
----some code here ---
end
end
A first guess is that the environment cron is setting up for your task isn’t the same as the one you use for development; are you using RVM or rbenv? Gemsets?
I have not been able to resolve this issue. Tried defining a relative path for log location in scheduler.rb file, but it didn’t help. I don’t see any log file after restarting cron job using: sudo service cron restart and the job as defined in Cron.sendAutomaticsSMS() is not executed.