Topic: Email Alerts

Hi all,

I'm building a property listing site. People can search for properties based on, no beds, min price, max price, town, etc.

I need a way of people to be able to save their searches as email alerts/updates and send these out at set intervals, daily, weekly, whatever.

So I'm guessing I'd have an alert model that saves all of the info about a search, no_beds, minprice, bla and user_id, frequency, expires_at.

I'm also guessing that you would use cron to send out the emails.

But how would the alerts controller work? How would it know when to send the emails? All users would save alerts at different times so all alerts would have different created_at times and frequencies (daily, weekly). And would you have to update a field to say when the next send date will be?

I'm hoping someone has implemented something similar, I've looked everywhere and can't really find much info on doing something like this, but it is a crucial part of any property website really.

Any help is appreciated as always!

Best wishes,
Steve

Re: Email Alerts

I would use cron to call into an action (using wget) to start the process, once a day, probably in the early morning hours.  I would probably then defer the actual processing into Backgroundrb.  I would probably have a frequency field (daily, weekly, monthly), and a last_emailed field.  Each day, you would obviously process all of the daily models.  You could also process the weekly models by selecting the alerts where last_emailed > 6.9 days ago.  Monthly gets funky (because of the inconsistency on number of days in a month) unless you want to just call 30.4375 days good enough.  For each alert that you've processed, you just update the last_emailed field.  Pretty simply, really.

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: Email Alerts

So would you say it is best to use BackgrounDRB, rather than RailsCron.

I kinda got the whole updating the last_emailed field. But the bit I really don't know how to do is to get BackgrounDRB or RailsCron to call the action that checks the frequency and date last emailed.  Plus when you do get this info, how will it link in to actually send the email.

Sorry if I'm asking daft questions, but I am fairly new to rails.

Cheers,
Steve

Re: Email Alerts

bkrahmer wrote:

...selecting the alerts where last_emailed > 6.9 days ago.  Monthly gets funky (because of the inconsistency on number of days in a month) unless you want to just call 30.4375 days good enough. ...

I don't have my references handy, but I thought ruby could do something like somedate - 1.month ?? I know its possible in SQL.