Greg Hauptmann
2007-Feb-12 23:02 UTC
How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
Hi, Is anyone able to clarify how I should, within a controller action, kick off a separate thread prior to finalising the action and rendering back to the browser. What I want to do is: a- enter action b- separate thread => Sleep 1 minute, then make HTTP request out to a separate application, no response is really required (this is to simulate a subsequent palpay IPN confirmation in my stub) c- main action (i.e. don''t wait for the above separate thread to complete for this) - perform neccessary steps and then render response back to browser. It''s step b I''m not sure how to implement? Thanks Greg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
bryanl
2007-Feb-12 23:10 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
On Feb 12, 6:02 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Is anyone able to clarify how I should, within a controller action, kick off > a separate thread prior to finalising the action and rendering back to the > browser. What I want to do is: > > a- enter action > b- separate thread => Sleep 1 minute, then make HTTP request out to a > separate application, no response is really required (this is to simulate a > subsequent palpay IPN confirmation in my stub) > c- main action (i.e. don''t wait for the above separate thread to complete > for this) - perform neccessary steps and then render response back to > browser. > > It''s step b I''m not sure how to implement? > > Thanks > GregDRB is most likely what you are looking for and Backgroundrb (http:// backgroundrb.rubyforge.org/) is a Rails plugin that makes it easy. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-13 08:42 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
thanks for the pointer Bryan - it seems somewhat a heavy weight solution for my seemingly simple requirement, however I guess if Ruby in general can''t handle a "fork" concept perhaps it is just as easy to install this plugin and use it... Cheers Greg On 2/13/07, bryanl <bryanliles-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On Feb 12, 6:02 pm, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > Hi, > > > > Is anyone able to clarify how I should, within a controller action, kick > off > > a separate thread prior to finalising the action and rendering back to > the > > browser. What I want to do is: > > > > a- enter action > > b- separate thread => Sleep 1 minute, then make HTTP request out to a > > separate application, no response is really required (this is to > simulate a > > subsequent palpay IPN confirmation in my stub) > > c- main action (i.e. don''t wait for the above separate thread to > complete > > for this) - perform neccessary steps and then render response back to > > browser. > > > > It''s step b I''m not sure how to implement? > > > > Thanks > > Greg > > DRB is most likely what you are looking for and Backgroundrb (http:// > backgroundrb.rubyforge.org/) is a Rails plugin that makes it easy. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sheldon Hearn
2007-Feb-13 08:59 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
On Feb 13, 10:42 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> thanks for the pointer Bryan - it seems somewhat a heavy weight solution for > my seemingly simple requirement, however I guess if Ruby in general can''t > handle a "fork" concept perhaps it is just as easy to install this plugin > and use it...Nothing to do with Ruby; ruby forks just fine. The problem is that your parent process can''t get on with the next HTTP request with an unreaped child out in the wild. In other words, this is an issue with the design of Rails (and many web frameworks in general), not Ruby. Try ask this question on a J2EE forum and see what you get. :-) Ciao, Sheldon. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-13 09:47 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
hi Sheldon - actually this might explain a timeout I was experiencing yesterday where I was creating a call from App A=>B, but then B was trying to do a separate confirmation (a 2nd HTTP request) back to A (a separate confirm action that A has) prior to finishing up in the controller action then rendering back to App A. I don''t quite understand where the blocking bottleneck occurs. If the rails action can spawn a new rails process which then itself creates a new HTTP request wouldn''t this be OK? Looking at the APIs the HTTP stuff seems to be in the Ruby Standard Library no (not the Rails API)? Tks Greg On 2/13/07, Sheldon Hearn <sheldonh-Uqlk7TKVmMlWaveUIWBRJg@public.gmane.org> wrote:> > > > > On Feb 13, 10:42 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > thanks for the pointer Bryan - it seems somewhat a heavy weight solution > for > > my seemingly simple requirement, however I guess if Ruby in general > can''t > > handle a "fork" concept perhaps it is just as easy to install this > plugin > > and use it... > > Nothing to do with Ruby; ruby forks just fine. The problem is that > your parent process can''t get on with the next HTTP request with an > unreaped child out in the wild. > > In other words, this is an issue with the design of Rails (and many > web frameworks in general), not Ruby. > > Try ask this question on a J2EE forum and see what you get. :-) > > Ciao, > Sheldon. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sheldon Hearn
2007-Feb-13 10:26 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
On Feb 13, 11:47 am, "Greg Hauptmann" <greg.hauptmann.r...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> hi Sheldon - actually this might explain a timeout I was experiencing > yesterday where I was creating a call from App A=>B, but then B was trying > to do a separate confirmation (a 2nd HTTP request) back to A (a separate > confirm action that A has) prior to finishing up in the controller action > then rendering back to App A.I think you''ll benefit enormously from the following mantra: Multiple threads and processes in a single request handler are illegal. It''s not true, but it''ll save you a whole lot of pain. If your second request can reasonably be completed in the context of this request, just handle it inline. If not, store the details of the request in the database and handle the processing thereof in a runner out of cron, or using one of the fun work distribution mechanisms. I remember seeing a very slick "clustered batch job manager", but forget its name and now can''t find it with Google. But anyway, the point is, stick to a single thread per request handler for a good time. :-) Ciao, Sheldon. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sheldon Hearn
2007-Feb-13 10:28 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
On Feb 13, 12:26 pm, "Sheldon Hearn" <sheld...-Uqlk7TKVmMlWaveUIWBRJg@public.gmane.org> wrote:> I remember seeing a very slick "clustered batch job manager", but > forget its name and now can''t find it with Google.It just came to me in a blinding flash of light: Starfish http://www.rufy.com/starfish/doc/ Ciao, Sheldon. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-13 10:29 UTC
Re: How to spawn separate thread within a controller action for a separate HTTP trigger to occur??
cheers - thanks for the clarification Sheldon Greg On 2/13/07, Sheldon Hearn <sheldonh-Uqlk7TKVmMlWaveUIWBRJg@public.gmane.org> wrote:> > > > On Feb 13, 12:26 pm, "Sheldon Hearn" <sheld...-Uqlk7TKVmMlWaveUIWBRJg@public.gmane.org> wrote: > > I remember seeing a very slick "clustered batch job manager", but > > forget its name and now can''t find it with Google. > > It just came to me in a blinding flash of light: Starfish > > http://www.rufy.com/starfish/doc/ > > Ciao, > Sheldon. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---