I prepared a simple task for testing CRON jobs on Amazon EC2:
schedule.rb
set :output, "/home/a/b/current/log/cron_log.log"
every 5.minutes do
#command "/usr/bin/some_great_command"
#runner "MyModel.some_method"
#rake "some:great:rake:task"
puts "It's working !!!"
runner "User.grab_first_user", :environment => 'development'
runner "User.grab_first_user", :environment => 'production'
end
user.rb
def self.grab_first_user
user = User.first
puts user.inspect
if user
NotificationMailer.send_info(user.email).deliver
end
end
notification_mailer.rb <-- this is workin
def send_info(user_email)
@user_email = user_email
mail(:to => 'my@emaill.com', :subject => "[CRON Test]")
end
When I check the crontab
file, I see there this CRON task, but the email is never sent - the method is never called.
When I manually call that method, then is everything working (also the email is sent), but the method is never called by CRON.
Am I missing something?