I would like to know how i should go about with this project. I need to send emails to people once a week. However this has to be auto generated and sent at a certain time every week. How hard is this to code? I need to know how if there are any books that could be of help or if any of you could direct me. It has to be programmed using ruby on rails. Hence there is a web service and database integrated. Cheers
Why is this complex?
All you need is to schedule a job. You can use Delayed::Job
for instance. Delayed::Job
gives you the possibility to schedule a job at specific time using the run_at
symbol like this:
Delayed::Job.enqueue(SendEmailJob.new(...), :run_at => scheduled_at)
Your job is a class that has to implement the perform
method. Inside this method you can call the mailer responsible for sending the email. The scheduled_at
can be stored on the database and updated each time the perform
method runs.
For books, chapter 6 of Rails Recipes is devoted to email. The book Advanced Rails Recipes has chapters on Asynchronous Processing and email. There are also railscast devoted to sending email and writing custom deamons.
You can use a gem like whenever
to schedule recurring tasks.
every :sunday, :at => '12pm' do
runner "User.send_emails"
end
Maybe you can try clockwork
require 'clockwork'
include Clockwork
handler do |job|
puts "Running #{job}"
end
every(10.seconds, 'frequent.job')
every(3.minutes, 'less.frequent.job')
every(1.hour, 'hourly.job')
every(1.day, 'midnight.job', :at => '00:00')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With