[Backgroundrb-devel] Can I do this, question

hemant kumar gethemant at gmail.com
Sat Apr 12 05:27:32 EDT 2008

On Fri, 2008-04-11 at 21:43 +0100, Ed W wrote:
> I have a bunch of real uses for BackgroundDrb, but I also a very simple 
> need to delay sending an email for about 5 seconds after a rails action 
> completes.  Basically I need to leave time for the DB to commit and sync 
> to the slaves before the email can be sent
> Is BackgroundDb the right tool for this job?  Any other suggestions on 
> ways to implement this?  (I have seen suggestions to create a new thread 
> and run the mailer from that thread, but it's not clear that 
> actionmailer is actually thread safe..?)
> I'm thinking just to fire up worker threads which pause for a length of 
> time before sending the email - is this likely the best solution?  Any 
> other suggestions?

you can use :

add_timer(5) { send_delayed_mail(mail_content_id) }

It will send all mails delayed by 5 seconds also, you should not use
sleep in your code to simulate "pause". sleep doesn't work well with
nonblocking IO reactor loops.

More information about the Backgroundrb-devel mailing list