I''m making a rails application that regularly sends out e-mails to users. While testing recently a controller got a timeout when trying to send an e-mail. => the mail server was down. Is there an easy way to handle something like this? Or do I have to handle a timeout-exception whereever sending of mail is initiated? I''m grateful for any help! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The best way is probably to have a queue that you store your emails in and then have a cron job to deliver them. I use railmail and modified it to work as a queue instead of immediately deliver the emails. You can wrap it in a timeout block also. It goes something like Timeout::timeout(10) do #send your email with a 10 second timeout end rescue Timeout::Error #log the error Thanks Fredrik On Aug 22, 6:09 am, Eivind Løland-Andersen <eivin...-nvIDUHlZTd3QT0dZR+AlfA@public.gmane.org> wrote:> I''m making a rails application that regularly sends out e-mails to > users. While testing recently a controller got a timeout when trying > to send an e-mail. => the mail server was down. > > Is there an easy way to handle something like this? Or do I have to > handle a timeout-exception whereever sending of mail is initiated? > > I''m grateful for any help!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 22, 4:11 pm, Fredrik <fredrik.thures...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The best way is probably to have a queue that you store your emails in > and then have a cron job to deliver them. I use railmail and modified > it to work as a queue instead of immediately deliver the emails. > > You can wrap it in a timeout block also. It goes something like > > Timeout::timeout(10) do > #send your email with a 10 second timeout > end > > rescue Timeout::Error > #log the error >Thanks! I think that timeout solution will do just fine. I agree that the best thing would be to put the e-mails into a queue, but in my app the e-mails are sendt as notifications, and must be sent immediately. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Eivind Løland-Andersen wrote:> > > On Aug 22, 4:11 pm, Fredrik <fredrik.thures...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> The best way is probably to have a queue that you store your emails in >> and then have a cron job to deliver them. I use railmail and modified >> it to work as a queue instead of immediately deliver the emails. >> >> You can wrap it in a timeout block also. It goes something like >> >> Timeout::timeout(10) do >> #send your email with a 10 second timeout >> end >> >> rescue Timeout::Error >> #log the error >> > Thanks! I think that timeout solution will do just fine. I agree that > the best thing would be to put the e-mails into a queue, but in my app > the e-mails are sendt as notifications, and must be sent immediately.You can send them immediately in a background process that can try several times if a timeout occurs before giving up. Take a look at http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails I''ve tried ap4r and backgroundrb. Both are not very well documented, however I found it easier to cope with ap4r. -- Sava Chankov --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
btw - as an alternative, try activemessaging - I use it for exactly this problem: http://code.google.com/p/activemessaging/ Cheers, -A On 8/23/07, Sava Chankov <sava.chankov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Eivind Løland-Andersen wrote: > > > > > > On Aug 22, 4:11 pm, Fredrik <fredrik.thures...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> The best way is probably to have a queue that you store your emails in > >> and then have a cron job to deliver them. I use railmail and modified > >> it to work as a queue instead of immediately deliver the emails. > >> > >> You can wrap it in a timeout block also. It goes something like > >> > >> Timeout::timeout(10) do > >> #send your email with a 10 second timeout > >> end > >> > >> rescue Timeout::Error > >> #log the error > >> > > Thanks! I think that timeout solution will do just fine. I agree that > > the best thing would be to put the e-mails into a queue, but in my app > > the e-mails are sendt as notifications, and must be sent immediately. > > You can send them immediately in a background process that can try > several times if a timeout occurs before giving up. Take a look at > http://wiki.rubyonrails.org/rails/pages/HowToRunBackgroundJobsInRails > > I''ve tried ap4r and backgroundrb. Both are not very well documented, > however I found it easier to cope with ap4r. > > -- > Sava Chankov > > > > >-- Andrew Kuklewicz --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Aug 22, 1:07 pm, Eivind Løland-Andersen <eivin...-nvIDUHlZTd3QT0dZR+AlfA@public.gmane.org> wrote:> Thanks! I think that timeout solution will do just fine. I agree that > the best thing would be to put the e-mails into a queue, but in my app > the e-mails are sendt as notifications, and must be sent immediately.Even though most mail servers use queues that does not mean they don''t immediately try to deliver email. You really are better off letting the mail server handle it rather than write your own mail server in Ruby. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---