문제

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')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top