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? Cheers Ed W
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.
hemant kumar wrote:> 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. > > >OK, cool. So if I want to delay the start by five seconds AND I expect the process I am running to take (say) 60 seconds to complete (some theoretical long running process), what''s the best way to structure that so that I don''t block the IO loop? Thanks Ed W