Question

As part of my app I am sending out an email to many users daily. Depending on their status they will be sent one of five possible types of emails.

The logic that determines which email the user receives is fairly long.

Should I:

1) Should I create a delayed_job for each email

or

2) Send the entire logic (50 lines of Ruby) with the send commands into a single job

What are the pros/cons of either approach?

Was it helpful?

Solution

Further to Sabyasachi Ghosh's answer, here are the differences between DelayedJob and Resque:

DelayedJob relies on the DB

  • Requires ActiveRecord
  • Uses Ruby Objects (not just references)
  • Has much deeper queuing functionality (queue depth etc)
  • Runs much heavier than resque

Resque relies on Redis

  • Lightweight
  • Runs independently of ActiveRecord
  • Is meant to process references (not entire objects)


Modularity

In answer to your question, I would look at modularity

Rails' is based on the principle of DRY code -- which essentially means you need to be as modular as possible (reusing code wherever you can). This leads to efficiency & simpler development cycles

In light of this, you have to observe your queueing functionality from the perspective of modularity. What does the queuing system actually do?


It queues things

Therefore, you want to include as little code as possible in the queuing system

I would create a redis instance (you can get them on Heroku), and use resque to queue specific information (such as id or email)

This will allow you to use resque to run through the Redis list, sending as many emails as you need

OTHER TIPS

If you have a huge logic i recommed not to put in the delayed job if you need to send a bunch of email. better use resque(https://github.com/resque/resque) or sidekiq(http://sidekiq.org/). as in the time of sending email it delayed job will lock your database so your performance will be low. If you have small logic and less number of email just go for delayed job for each email. as it is easy to setup and implement.

I think so you need to send each email via delayed job because if anything happens with your delayed job like if your delayed job get crashed or stopped in that case when system will re execute your job it can cause problems so i suggest you to add each email in delayed job.

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