Hi, I am going to use BackgrounDRb for to handle some processing, but have one question that I haven''t been able to find in the documentation. I have an application that accepts XML docs via a HTTP POST. I am going to hand the processing of the XML doc to worker, so that I can send back a HTTP REPLY right away. It seems that you need to make an explicit call to worker.delete to stop it from running. My question is, is there an easy way for the worker to delete itself after running its do_work method, or a way to notify the main application that it has completed the processing and is ready to be deleted? Thanks, Simon --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi Simon, Simon wrote:> is, is there an easy way for the worker to delete itself after running > its do_work method, or a way to notify the main application that it > has completed the processing and is ready to be deleted?Add the following two lines at the bottom of your do_work method. ActiveRecord::Base.connection.disconnect! ::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key The first ensures that the database connection has been closed and the second kills the worker. hth, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, I tried adding those two lines to the bottom of my do_work method, and am now getting the following error on the second line (::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key) 20070405-13:15:15 (19653) In do work 20070405-13:15:18 (19653) You have a nil object when you didn''t expect it! The error occured while evaluating nil.shutdown - (NoMethodError) 20070405-13:15:18 (19653) /usr/local/src/rails/434Wireless/vendor/ plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:373:in `delete_worker'' 20070405-13:15:18 (19653) /usr/local/src/rails/434Wireless/lib/workers/ parser_worker.rb:657:in `do_work'' Any ideas what the issue might be? Thanks again, Simon On Mar 22, 9:34 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Simon, > > Simon wrote: > > is, is there an easy way for the worker to delete itself after running > > its do_work method, or a way to notify the main application that it > > has completed the processing and is ready to be deleted? > > Add the following two lines at the bottom of your do_work method. > > ActiveRecord::Base.connection.disconnect! > ::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key > > The first ensures that the database connection has been closed and the > second kills the worker. > > hth, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Simon wrote:> Hi, > > I tried adding those two lines to the bottom of my do_work method, and > am now getting the following error on the second line > (::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key)It seems like @_job_key is nil. -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Yes, it does. What I''m trying to do is to delete the worker from inside its own do_work method, so that the main Rails app creates a new worker instance, and then the worker does some work, and deletes itself. Is there another method to accomplish this? Thanks, Simon On Apr 5, 1:30 pm, Wai Tsang <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Simon wrote: > > Hi, > > > I tried adding those two lines to the bottom of my do_work method, and > > am now getting the following error on the second line > > (::BackgrounDRb::MiddleMan.instance.delete_worker @_job_key) > > It seems like @_job_key is nil. > > -- > Posted viahttp://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---
Simon wrote:> Yes, it does. What I''m trying to do is to delete the worker from > inside its own do_work method, so that the main Rails app creates a > new worker instance, and then the worker does some work, and deletes > itself. Is there another method to accomplish this? > > Thanks, > > SimonI''ve done a lot of playing around and so I''ll post this for others who might find this page via google. I noticed that when I used the above method, delete_worker that the worker wouldn''t be deleted. It would just hang around. Even though the worker was done working, but Middleman.get_work(key) would still return a worker!!! *sigh* Anyway, I then dug around the code of backgrounDRb and found kill_worker which i added to the of the do_work method. And low and behold, workers were dying! ActiveRecord::Base.connection.disconnect! ::BackgrounDRb::MiddleMan.instance.kill_worker @_job_key Also FYI, I also noticed in other posts that @_job_key was returning nil while @job_key wasn''t. Just putting that out there. Cheers -- Posted via http://www.ruby-forum.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 -~----------~----~----~----~------~----~------~--~---