Hello Rails community, I would like to get some advices - I am writing a web application that will be sending some emails and execute other long running tasks. Some of these tasks may take some time and I do not want the user experience to be impacted. I would appreciate any pointers on advices on these areas: * how to send emails without making the user wait * how to execute long running tasks * The best way to do periodic cron jobs in Rails Thank you for your help in advance. Chris
Chris wrote:> * how to send emails without making the user waitEither Thread.new{}, or a plugin called Spawn. You need the latter if your e-mails call templates which in turn call ActiveRecord. A separate thread requires a separate database connection, and Spawn handles this.> * how to execute long running tasksThe threading option has one flaw: If your web server expunges your Passenger module from memory, the thread lapses. When sending a few emails, if you can''t send them before process harvesting time, you have bigger problems than a missing email. Failing that analysis, you need an out-of-process solution like BackgroundRB. It runs in a daemon of its own and communicates with your app thru dRB. In exchange for a fatter and more fragile implementation, you get a process you can control directly. However...> * The best way to do periodic cron jobs in RailsCreate a folder called cron, write (using TDD!) a script that does what you need, and install it into your OS''s cron system as the command line script/runner lib/my_script.rb. If I needed to send e-mails, I would pool them up, then push them out with a cron. The previous two options allow communication back to the user in subsequent controller actions. You probably don''t need that, so just configure a cron to run every 90 seconds, and send emails for up to 1 minute. Take a little care to not send the same email twice, and you are set. -- Phlip http://flea.sourceforge.net/resume.html
For emails, the simplest way is to set up a local MTA (postfix, for instance) and send the mail to that. The MTA takes care of the hard part delivering the mail as needed. For more general things, there are some gems that let you set up cron- like tasks, or you can just call a rake task from plain old cron. --Matt Jones On Jun 6, 8:23 pm, Chris <chrisn...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Rails community, > > I would like to get some advices - I am writing a web application > that will be sending some emails and execute other long running tasks. > > Some of these tasks may take some time and I do not want the user > experience to be impacted. I would appreciate any pointers on advices > on these areas: > > * how to send emails without making the user wait > * how to execute long running tasks > * The best way to do periodic cron jobs in Rails > > Thank you for your help in advance. > > Chris
Two pointers from personal experience: 1. Don''t use backgroundrb for asynchronous processing 2. Do use javan-whenever to automate your cron jobs (available on Github) Bharat
@Bharat, Can you give brief why to use javan instead backgroundrb ? As, i am using backgroundrb for heavy upload duties and it works fine for me. - Sandip R~ On Sun, Jun 7, 2009 at 11:26 PM, Bharat <bcruparel-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote:> > Two pointers from personal experience: > > 1. Don''t use backgroundrb for asynchronous processing > 2. Do use javan-whenever to automate your cron jobs (available on > Github) > > Bharat > > > >-- Ruby on Rails Developer http://sandip.sosblog.com http://funonrails.wordpress.com www.joshsoftware.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks a lot for the pointers and the great suggestions. I really do find BackgrounDrb too heavy for my implementation - and think the gems you described make sense. Spawn plugin and Javan-whenever is great. And there is a Railscast that is really good in explaining: http://railscasts.com/episodes/164-cron-in-ruby On Jun 8, 7:35 am, Sandip Ransing <san2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> @Bharat, > > Can you give brief why to use javan instead backgroundrb ? > As, i am using backgroundrb for heavy upload duties and it works fine for > me. > > - Sandip R~ > > On Sun, Jun 7, 2009 at 11:26 PM, Bharat <bcrupa...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > Two pointers from personal experience: > > > 1. Don''t use backgroundrb for asynchronous processing > > 2. Do use javan-whenever to automate your cron jobs (available on > > Github) > > > Bharat > > -- > Ruby on Rails Developerhttp://sandip.sosblog.comhttp://funonrails.wordpress.comwww.joshsoftware.com
I would highly recommend using delayed_job ( http://github.com/tobi/delayed_job/tree/master). We''ve recently integrated this into the BioCatalogue (http://www.biocatalogue.org) to great effect. This is what GitHub use I believe (http://github.com/blog/197-the-new-queue ). Useful blog post that walks you through setting up delayed_job - http://www.magnionlabs.com/2009/2/28/background-job-processing-in-rails-with-delayed_job Useful FAQ: http://wiki.github.com/tobi/delayed_job Examples: http://github.com/igal/rubyqueues/tree/master/delayed_job_eg/ Comparisons: http://github.com/igal/rubyqueues/raw/802998678c012ed17b27324a41a4cd42a377a678/comparison.html Hope that helps. Jits 2009/6/13 Chris <chrisnow7-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>> > Thanks a lot for the pointers and the great suggestions. > > I really do find BackgrounDrb too heavy for my implementation - and > think the gems you described make sense. > > Spawn plugin and Javan-whenever is great. And there is a Railscast > that is really good in explaining: > http://railscasts.com/episodes/164-cron-in-ruby > > > On Jun 8, 7:35 am, Sandip Ransing <san2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > @Bharat, > > > > Can you give brief why to use javan instead backgroundrb ? > > As, i am using backgroundrb for heavy upload duties and it works fine for > > me. > > > > - Sandip R~ > > > > On Sun, Jun 7, 2009 at 11:26 PM, Bharat <bcrupa...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> wrote: > > > > > Two pointers from personal experience: > > > > > 1. Don''t use backgroundrb for asynchronous processing > > > 2. Do use javan-whenever to automate your cron jobs (available on > > > Github) > > > > > Bharat > > > > -- > > Ruby on Rails Developerhttp://sandip.sosblog.comhttp:// > funonrails.wordpress.comwww.joshsoftware.com > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---