I create a reservation system in Rails 4.2, where I need to send a set of letters to users at predefined intervals (for example, they have an upcoming reservation, feedback after that, a link to change / cancel an existing reservation, etc.). I looked around and found this and this , but I'm trying to choose between approaches.
I see two main ways to build this system.
Using a queuing system, such as delayed_job . Whenever someone makes a reservation, we queue all letters for the correct time when they should be sent.
Pro: one line for all emails. Automatic repeat logic.
Con: Thousands of letters end up in the queue in the system. You need to deactivate every time someone cancels the reservation (it depends: itβs quite easy to destroy messages associated with it). Somewhat more complex logic at what time we need emails to exit.
cron + rake task that runs at a predetermined interval (hourly? every fifteen minutes?) and checks the emails to be sent. It executes a query such as "Find all reservations that are in three days," and then sends all emails.
Pro: Put everything in the application logic, reduce the number of states that we need to track.
Con: you need to keep track of which letters were sent, which conceptually looks like any task table that we have already created above.
source share