BackgrounDRb question

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

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

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:indo_work’

Any ideas what the issue might be?

Thanks again,

Simon

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.

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

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,

Simon

I’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