Sazzad
Sazzad

Reputation: 853

Cron job not working for Whenever gem

I have an application that contains a bunch of tasks, and every 3 minutes I want to run a cron job that sends a mail for some test. I'm using the whenever gem but it doesn't seem to be running at all.Any ideas?

config/schedule.rb

every 3.minutes do
  runner "MailerClass.some_method"
end

MailerClass.rb

def some_method
  mail(:to => "some email", :cc => 'some email', :subject => "Regular Email by rake task #{Time.now.strftime("%H : %m")}", :from => "[email protected]") do |format|
  end
end

What I have Tried after modifing config/schedule.rb are,

whenever --update-crontab --set environment=development
sudo service cron restart

When I run crontab -l this is the output

0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /bin/bash -l -c 'cd /home/my_app && script/rails runner -e development '\''MailerClass.some_method'\'' >> log/notification.log 2>&1'

I have checked the log. The problem is script/rails: line 6: syntax error near unexpected token (' script/rails: line 6:APP_PATH = File.expand_path('../../config/application', FILE)'

I am not getting this. I am new to rails. Thats why may be :(.

Any Solution!!!

Upvotes: 0

Views: 184

Answers (2)

Ashutosh Tiwari
Ashutosh Tiwari

Reputation: 998

Based on your updated info i am updaing my answer
Remove last single quote form end of parenthesis form this line APP_PATH = File.expand_path('../../config/application', FILE)'

Upvotes: 0

Ismael
Ismael

Reputation: 16720

It looks like you are forgetting to actually send the email

Instead of

MailerClass.some_method

try

MailerClass.some_method.deliver

Upvotes: 0

Related Questions