Whenever a user sends another user a message, my app delivers an email
notification to the recipient. Unfortunately, the email delivery process
creates a short delay. Any thoughts on how to remove this delay? Would
calling the delivery method with a after_filter be the right way to go?
Thanks.
The after_filter might mask the delay... I've never used it, but another option would be to store the message info in a table and process it with a background process out of cron every minute or so (or shoot it off to backgroundrb for processing)...
-p
The method of running a cron that often isn't really a good idea,
especially if you're not running on top of the line hardware. It will
load up the whole environment, execute that one tiny task and exit. What
I've done in cases like this is write a long-running(read: infinite)
class method that checks for the condition, executes its task and then
waits 30 seconds or so. Yes, you still have an extra copy of the app in
memory, but you're not using up cpu and disk resources like you would
loading everything up every minute.
Jason
Philip Hallstrom wrote:
Chet,
The observer class looks interesting, and I may use it in a project I'm working on, but I don't think the situation I had could use Observer.
Basically, the app is an Ebay-style auction site. I have lots which have an expiration time and a status. My daemon goes and queries the database for lots that are "Open" but whose end time has passed. If it finds one, it closes the lot, logs a purchase and sends emails to the buyer and seller.
It is really clunky having an external process like that running, and a bit unreliable - the app could be running fine, but without the daemon, lots will never get properly closed and no one will get emails about them.
If you know of any other way to implement something like this, I'd be happy to hear about it.
Jason
Chet wrote: