How do I organize my models and the cron rake task to send email at intervals with different start dates?

I overestimate my model and the way I try to solve a specific problem. I have Contacts that may belong to the Campaign, which is a series of actions, such as phone calls and emails, each of which is assigned within a few days as an attribute that determines when it should be sent.

I want cron to look at and view emails that should be today (or maybe expired), and discard those emails.

All contacts have their own start dates.

Once a call, which should take place, say, in 6 days from the very beginning, is not made up to 10 days. This means that e-mail in the same campaign, which must be completed 8 days from the beginning, should be postponed for another 4 days, up to 12 days from the beginning, but only for this specific contact if the deferred call was for the contact.

I would like people to come closer to modeling this and, in particular, to come up with the right emails any day to send.

Some issues that I encountered with my approach:

1) When there is no email to send, I am mistaken with zero. I try to catch him wondering if there is a better way to check. How do people deal with this?

2) How do you calculate the cascade delay? I use a sophisticated way to first check the last date of everything that has been completed (completed elements have their own entries in ContactEmail or ContactCalls, for example). Then I find the difference in interval versus the days attribute. Then I add this interval to the end date of the last item.

+4
source share
3 answers

I would also suggest using delayed_job to handle sending emails. With delayed_job, you will have a task queue with appropriate times. This allows you to plan tasks at a specific time in the future. This is probably more convenient than using cron.

As for scheduling, it seems to me that the letter is not sent until the call is completed, so the queued email entry should be created at the moment the application is notified of the completion of the call. Calculating the date should be as simple as Time.now + 4.days .

If more than one call is required before releasing an email, you just need to check that ALL calls have been completed before you put the email in the queue for sending.

+1
source

Have you tried managing this through delayed_job? I had tremendous success when he did such things, and you have all the amenities in the Rails stack instead of going to cron or rake.

0
source

1) When there is no email to send, I have a zero error. I try to catch him, I wonder if there is a better way to check. How do people deal with this?

Check zero. If it is zero, do nothing.

2) How do you calculate the cascade delay? I use a complicated method by first checking the last date for everything that has been completed (completed elements have their own entry in ContactEmail or ContactCalls for an example). Then I find the difference between the days attribute. Then I add this interval to the date of the last item.

Itโ€™s a little embarrassing how you described it, but it seems that the โ€œLettersโ€ should take place 4 days after the โ€œCallsโ€. Thus, in your rake task of making emails, just find all the calls that were completed 4 more than 4 days ago without any corresponding letters, and then send them by email.

0
source

All Articles