0

I try to create a mailing list feature in Rails which is based on delayed_jobs. For now I send mails by iterating over a users table and .deliver a mail to every mail address.

how can i integrate it into delayed_jobs, so it sends 50 mails every 5 minutes and remembers which adresses are already done? do i need to make a seperate table where i store all sent mails and check back everytime i send another 50 mails?

thanks in advance.

trnc
  • 20,581
  • 21
  • 60
  • 98
  • 2
    Your question is basically "how do I write the entire application", and the only way we could answer is to write it for you. That isn't what SO is for. Try it, and when you get stuck on a specific problem, come back and ask for help. – user229044 Sep 08 '11 at 23:49
  • You know I really don't see that. – mark Sep 09 '11 at 20:19

3 Answers3

4

You will probably want to have table entries for sent emails. That way it serves as an audit trail if processes go down or somehow fail.

Suggest you look at doing this with an elastic cloud database like MongoLab, MongoHQ or SimpleDB. (Mongo-based services make it easy to extend the schema for new email entries.)

If you do that, then a cloud worker queue like SimpleWorker can make it easy to send out lots of emails concurrently or in batches to get around any rate limits. (full disclosure: I work at Iron.io/SimpleWorker)

You're taking a good approach to bundle multiple email sends into a single worker task to amortize the worker setup costs. With an elastic cloud worker system, you could have master workers come off schedule and then queue up a number of slave worker tasks, each with a set of users to send.

With table entries, you can then go back through the data tables and address any emails that failed or didn't go through.

Ken Fromm
  • 91
  • 2
0

50 emails is not really so much can be sent in seconds, I think. Use foreverb for sending emails every 5 minutes.

Dmitry Maksimov
  • 2,861
  • 24
  • 19
0

Let delayed job do all the work:

User.all.each_with_index |user, index|
  Mailer.delay({:run_at => ((index / 50) * 5).minutes.from_now}).send_newsletter(user)
end

This should work but untested.

mark
  • 10,316
  • 6
  • 37
  • 58