Question

I need to send some emails weekly. I installed the mailer and did several tests. Is working properly.

But I can not use Whenever to automatically send emails. Have searched in various forums and still can not fix.

Model/HrCurriculumIntern

def self.send_reply_interns
  @users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))
  InternMailer.send_reply_interns(@users).deliver
end

Mailer/InternMailer

default :from => "username.mailer@gmail.com"

def send_reply_interns(users)
  @users = users   
  mail(:to => "<lorenadgb@gmail.com>", :subject => t('subjects.send_reply_interns'), :from => "username.mailer@gmail.com")
end

COnfig/schedule.rb

set :environment, :development

every 2.minutes do
 runner "HrCurriculumInterns.send_reply_interns"
end

I followed this steps: Eu segui estes passos:

wheneverize .

whenever

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

whenever –update-crontab

 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd /var/www/form/3216/email/trunk && script/rails runner -e development '\''HrCurriculumInterns.send_reply_interns'\'''

 ## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
 ## [message] Run `whenever --help' for more options.

I can't see the problem, any suggestion please?

Was it helpful?

Solution

Use the shortcut "whenever -w" to write the crontab. It looks like you used "whenever -update-crontab" instead of "whenever --update-crontab". So neither of your commands actually wrote the crontab file. The response should be

[write] crontab file updated

After that use "crontab -l" to verify that the correct cron was written.

OTHER TIPS

I found the solution.

My code was wrong. I did some alterations:

Mailer/intern_mailer.rb

def send_reply_interns
  @users = HrCurriculumIntern.where(:answer_sent => t('labels.n'))  
  mail(:to => "<lorenadgb@gmail.com>", :subject => t('subjects.send_reply_interns'), :from => "username.mailer@gmail.com")
end

Models/hr_curriculum_intern.rb

def self.send_reply_interns
  InternMailer.send_reply_interns.deliver
end

schedule.rb

set :environment, :development

every 2.minutes do
  runner "HrCurriculumIntern.send_reply_interns"
end

Its works now \ o /

Thanks for reply

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top