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.
-Brent
On Fri, Sep 19, 2008 at 11:14 PM, Mitchell Curtis Hatter <
[EMAIL PROTECTED]> wrote:
> Just starting out with BackgroundDRb and have some troubles with calling a
> worker's async process right after I try to create it.
>
> Here's my code:
>
> In my book model I have the following:
>
> # Starts a new BackgroundDRb worker for searching
> def start_search(worker_key, job_key, search_params)
> MiddleMan.new_worker(:worker => :texis_worker, :worker_key =>
> worker_key.to_s)
> MiddleMan.worker(:texis_worker, worker_key.to_s).async_search(:arg =>
> {:book => self, :search_params => search_params}, :job_key => job_key)
> end
>
> # Get Status of Worker
> def self.search_status(worker_key, job_key)
> status = MiddleMan.worker(:texis_worker,
> worker_key.to_s).ask_result("#{worker_key.to_s}_#{job_key.to_s}")
> end
>
> My controller's search method has this line:
>
> @book.start_search(session[:user], @book.id, search_params)
>
> Here's my worker:
>
> class TexisWorker < BackgrounDRb::MetaWorker
> set_worker_name :texis_worker
> set_no_auto_load true
>
> def create(args = nil)
> logger.info "Creating #{worker_key}"
> end
>
> def search(arg)
> logger.info "Testing #{worker_key} -- #{job_key} -- #{arg[:book].name}"
> cache["#{worker_key.to_s}_#{job_key.to_s}"] = arg[:book].name
> end
> end
>
>
> 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.
>
> I tail the log and then browse to the controller. In my log I will get:
> Creating 293460168
>
> But nothing else.
>
> Eventually, say 30 seconds to a minute and switching between different
> books I finally start to get something like:
> Testing 293460168 -- 3806 -- Workers Compensation
>
> If I do this from script/console everything works fine.
>
> I'm running mongrel in development mode, using packet 0.1.13, backgroundrb
> 1.0.4, cent os 5
>
> 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?
>
> Any help would be appreciated.
>
> Thanks,
> Curtis
> _______________________________________________
> Backgroundrb-devel mailing list
> [email protected]
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>
--
Brent Collier | 919.564.6915 | www.BrentCollier.com | www.acts-as-blogr.com
_______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel