Reputation: 3
I used when ever gem to send mails every day but it's not sending.I am using amazon linux ec2
instance. Please look at my code once.
schedule.rb:
every 5.minutes do
runner "Listings.today_expired_spaces"
end
Listings.rb:(model-file)
def today_expired_spaces
@list=List.find_by_date(Date.today)
UserMailer.today_expired_list(@list).deliver
end
In production:
After running these commands I am getting responses like this
1.whenever -w
[write] crontab file written
2.whenever -i [write] crontab file updated
3.whenever
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /bin/bash -l -c 'cd /home/ubuntu/my_server && bundle exec script/rails runner -e production '\''Spaces.today_expired_spaces'\'''
[message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
[message] Run `whenever --help' for more options.
Please provide solution to this.
Upvotes: 0
Views: 1351
Reputation: 202
you should make a rake task
in lib/tasks
folder and include the task to whenver schedule file in config/schedule.rb
in lib/tasks/send_mail_bang_bang.rake
(filename just for example only)
require 'rake'
namespace :task_namespace do
desc 'task description'
task :send_mail => :environment do
# call Listing method to send mail
Listings.today_expired_spaces
end
end
in config/schedule.rb
every 5.minutes do
rake 'task_namespace:send_mail'
end
you can read more about rake task here in "custom-rake-tasks" part
hope it helps
Upvotes: 1