On 05.09.2007, at 18:40, Ed -- wrote:

>> I rebuild my index in a separate process and directory. When it's
>> done, I tell the index server via DRb that a new index is available
>> and it'll switch to the new directory. Works like a charm.
>
> Do you use backgroundrb for this?. I'm coming up against similar
> problems with long running processes which need an ActiveRecord
> connection. I briefly tried to use fork() to background it but that
> seemed to give me problems with acts-as-authenticated.

I use fork without problems. Here's a snippet from my controller  
which triggers the rebuild:

     def exec_command(command)
       dbconfig = ActiveRecord::Base.remove_connection
       fork do
         begin
           ActiveRecord::Base.establish_connection(dbconfig)
           `cd #{RAILS_ROOT} && script/runner -e #{ENV['RAILS_ENV']}  
'#{index_class}.#{command}'`
         ensure
           ActiveRecord::Base.remove_connection
         end
       end
       ActiveRecord::Base.establish_connection(dbconfig)
     end

As you can see, I'm actually running a shell script which starts a  
whole new Rails process via script/runner. Note that  
ActiveRecord::Base.allow_concurrency is NOT set to true.

I don't remember why this remove/establish connection was necessary,  
but it's definitely needed.

Cheers,
Andy

_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to