<div dir="ltr">Yeah, you pretty much have to throw a sleep call in between creating the worker and actually asking it to do work. It only takes a fraction of a second. I was told this was only a problem on OS X, but I've also witnessed it on Gentoo. I see this question on the mailing list enough that I think it might as well be included in the docs somewhere.<br>
<br>-Brent<br><br><br><div class="gmail_quote">On Fri, Sep 19, 2008 at 11:14 PM, Mitchell Curtis Hatter <span dir="ltr"><<a href="mailto:curtis.hatter@insightbb.com">curtis.hatter@insightbb.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Just starting out with BackgroundDRb and have some troubles with calling a worker's async process right after I try to create it.<br>
<br>
Here's my code:<br>
<br>
In my book model I have the following:<br>
<br>
# Starts a new BackgroundDRb worker for searching<br>
def start_search(worker_key, job_key, search_params)<br>
MiddleMan.new_worker(:worker => :texis_worker, :worker_key => worker_key.to_s)<br>
MiddleMan.worker(:texis_worker, worker_key.to_s).async_search(:arg => {:book => self, :search_params => search_params}, :job_key => job_key)<br>
end<br>
<br>
# Get Status of Worker<br>
def self.search_status(worker_key, job_key)<br>
status = MiddleMan.worker(:texis_worker, worker_key.to_s).ask_result("#{worker_key.to_s}_#{job_key.to_s}")<br>
end<br>
<br>
My controller's search method has this line:<br>
<br>
@book.start_search(session[:user], @<a href="http://book.id" target="_blank">book.id</a>, search_params)<br>
<br>
Here's my worker:<br>
<br>
class TexisWorker < BackgrounDRb::MetaWorker<br>
set_worker_name :texis_worker<br>
set_no_auto_load true<br>
<br>
def create(args = nil)<br>
<a href="http://logger.info" target="_blank">logger.info</a> "Creating #{worker_key}"<br>
end<br>
<br>
def search(arg)<br>
<a href="http://logger.info" target="_blank">logger.info</a> "Testing #{worker_key} -- #{job_key} -- #{arg[:book].name}"<br>
cache["#{worker_key.to_s}_#{job_key.to_s}"] = arg[:book].name<br>
end<br>
end<br>
<br>
<br>
When a user runs a search in my books controller I call start_search passing in a user id as the worker_key, book_id as job_key and a hash of search parameters.<br>
<br>
I tail the log and then browse to the controller. In my log I will get:<br>
Creating 293460168<br>
<br>
But nothing else.<br>
<br>
Eventually, say 30 seconds to a minute and switching between different books I finally start to get something like:<br>
Testing 293460168 -- 3806 -- Workers Compensation<br>
<br>
If I do this from script/console everything works fine.<br>
<br>
I'm running mongrel in development mode, using packet 0.1.13, backgroundrb 1.0.4, cent os 5<br>
<br>
It seems initially creating the worker is not done for a while? and so the calls to async are failing; once the worker has been intialized everything is fine?<br>
<br>
Any help would be appreciated.<br>
<br>
Thanks,<br>
Curtis<br>
_______________________________________________<br>
Backgroundrb-devel mailing list<br>
<a href="mailto:Backgroundrb-devel@rubyforge.org" target="_blank">Backgroundrb-devel@rubyforge.org</a><br>
<a href="http://rubyforge.org/mailman/listinfo/backgroundrb-devel" target="_blank">http://rubyforge.org/mailman/listinfo/backgroundrb-devel</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>Brent Collier | 919.564.6915 | <a href="http://www.BrentCollier.com">www.BrentCollier.com</a> | <a href="http://www.acts-as-blogr.com">www.acts-as-blogr.com</a><br>
</div>