views:

69

answers:

2

I'm re-evaluating my model and way I am trying to solve a particular problem. I have Contacts that can belong to a Campaign, which is a series of activities such as phone calls and emails, each with a number of days assigned as an attribute determining when it should get sent.

I want the cron job to look and see emails which are due today (or maybe overdue) and fire off those emails.

Contacts all have their own separate start-dates.

Sometime a Call, which needs to take place, say, 6 days from the start, doesn't get done until 10 days. That means the email in the same campaign, set to be done 8 days from the start, needs to be delayed by 4 more days, to 12 days from the start, but only for that particular contact if the delayed Call was for the Contact.

I would like from people how they would approaching modeling this and, in particular, come up with on any given day, the right Emails to send.

Some challenges I have encountered with my approach:

1) When there is no email to send, I error out with nil. I try to catch it, wondering if there's a better way to check. How do people handle that?

2) How do you calculate the cascade delay? I use a complicated way of first checking the last date of everything that was completed (completed items have their own record in ContactEmail or ContactCalls for example). I then find the difference in the interval against the attribute 'days.' Then I add that interval to the date that last item was completed.

A: 

Have you tried managing this through delayed_job instead? I've had huge success with it doing similar things, and you have all the comfort of the Rails stack instead of going to cron or rake.

AKWF