[Backgroundrb-devel] Trouble using backgroundrb

Ger Apeldoorn gapeldoorn at wehkamp.nl
Tue Sep 25 02:27:26 EDT 2007


Hi Tieg,

Unfortunately, it is not that easy. I've tried your suggestions, but
they didnt work. If I put the worker-class in the same file as the
controller, I get 'uninitialized constant BackgrounDRb::Worker' instead
of 'uninitialized constant Passwd'.

Now, I've generated a non-namespaced worker, which gives the same
results! (uninitialized constant GetPasswds)

Shouldn't I include anything into environment.rb or something?

Thanks again,
Ger.

On Mon, 2007-09-24 at 10:22 -0400, Tieg Zaharia wrote:
> Hey Ger,
> 
> This should be pretty easy. You just need to initialize the Module
> name, which you could do like this:
> 
> module Passwd
>   class GetPasswdsWorker
>   ...
>   end
> end
> 
> or you could initialize it and then wrap it like this: 
> 
> module Passwd end
> class Passwd::GetPasswdsWorker
>   ...
> end
> 
> That should work, but is there any specific reason to namespace it?
> Could you just call the class PasswdWorker?
> 
> 
> -tieg
> 
> On 9/24/07, Ger Apeldoorn <gapeldoorn at wehkamp.nl> wrote:
>         Hi Tieg,
>         
>         Thanks a lot for your reply!
>         
>         Unfortunately, I'm not there yet.. After I adapt the
>         new_worker call,
>         this is the error I get:
>         
>         uninitialized constant Passwd
>         
>         So, it really doesnt know how to handle namespaces it appears.
>         Can you 
>         see any way to get around that? If I generate the worker
>         without the
>         namespace, can I call it from within the passwd namespace?
>         
>         Thanks again,
>         Ger.
>         
>         On Mon, 2007-09-24 at 09:59 -0400, Tieg Zaharia wrote: 
>         > I'm not sure if this is your problem, but I think you should
>         include
>         > two colons in the worker klass name, like this:
>         >
>         > ...new_worker(:class => "passwd::get_passwds_worker", :args
>         => "")... 
>         >
>         > Also, BackgrounDRb uses a method in the middleman.rb file
>         called
>         > worker_klass_constant(), from whence it derives the constant
>         name.
>         > This is the constant that BackgrounDRb will look for after
>         passing 
>         > your class name to that method:
>         >
>         > "Passwd::getPasswdsWorker"
>         > (whereas you want Passwd::GetPasswdsWorker)
>         >
>         > That might be a bug (or a feature enhancement if BDrb
>         doesn't support 
>         > namespaced workers yet), so the right way would be to patch
>         that
>         > method. Orrr, you could just pass the real name of the
>         worker in your
>         > controller, like this..
>         >
>         > session[:job_key] = MiddleMan.new_worker (:class =>
>         > "Passwd::GetPasswdsWorker", :args => {})...
>         >
>         >
>         > -tieg
>         >
>         >
>         > On 9/24/07, Ger Apeldoorn <gapeldoorn at wehkamp.nl> wrote:
>         >         Hi all,
>         >
>         >         I'm a newbie to backgroundrb and am having trouble
>         integrating
>         >         it into
>         >         my rails-app. I'm using namespaces to differentiate
>         between 
>         >         the parts of
>         >         my app.
>         >
>         >         When I want to create a new worker, it seems that it
>         cannot
>         >         find the
>         >         worker object. Here's my code:
>         > 
>         >         -------------------- controller app/passwd/index
>         >         --------------------
>         >         class Passwd::IndexController <
>         ApplicationController
>         >           layout 'default'
>         >
>         >           def index
>         >             $subtitle = "AIX user inventory tool"
>         >           end
>         >
>         >           def createReport
>         >             Passwdentry.delete_all
>         >             User.delete_all
>         >             session[:job_key] = MiddleMan.new_worker(:class
>         =>
>         >         "passwd:get_passwds_worker", :args => "")
>         >           end
>         >
>         >           def get_progress 
>         >             if request.xhr?
>         >               progress_percent =
>         >         MiddleMan.get_worker(session[:job_key]).progress
>         >               render :update do |page|
>         >                 page.call ('progressPercent', 'progressbar',
>         >         progress_percent)
>         >                 page.redirect_to( :action => 'done') if
>         >         progress_percent >= 100
>         >               end 
>         >             else
>         >               redirect_to :action => 'index'
>         >             end
>         >           end
>         >
>         >           def done
>         >             render :text => "De database is bijgewerkt" 
>         >             MiddleMan.delete_worker(session[:job_key])
>         >           end
>         >         end
>         >
>         >
>         --------------------lib/workers/get_passwds_worker.rb--------------------
>         >         # Put your code that runs your task inside the
>         do_work method 
>         >         it will be
>         >         # run automatically in a thread. You have access to
>         all of
>         >         your rails
>         >         # models.  You also get logger and results method
>         inside of
>         >         this class 
>         >         # by default.
>         >         class Passwd::GetPasswdsWorker <
>         >         BackgrounDRb::Worker::RailsBase
>         >           attr_reader :progress
>         >           def do_work(args)
>         >             @progress = 0 
>         >             @progressinterval = 100/System.count
>         >             System.find_all.each do |sys|
>         >               getAndParsePasswdFile(sys.name )
>         >               @progress += @progressinterval 
>         >             end
>         >           end
>         >
>         >           def getAndParsePasswdFile(sys)
>         >             output = %x[some command-line-magic ;)]
>         >             output.each do |outputline|
>         >               outputline = outputline.split (":")
>         >               thisline = Passwdentry.new
>         >               thisline.setvalues(outputline[0], sys,
>         outputline[2]);
>         >               thisline.save
>         >             end
>         >           end
>         >         end
>         >         Passwd::GetPasswdsWorker.register
>         >
>         >
>         --------------------app/views/passwd/index/createReport.rhtml--------------------
>         >         <h2>De database wordt voorzien van de laatste
>         data.</h2> 
>         >         <div id='progressbar' class="progress"></div>
>         >         <%= periodically_call_remote(:url => {:action =>
>         >         'get_progress'}, :frequency => 1) %> 
>         >
>         >
>         --------------------conf/backgroundrb.yml--------------------
>         >         ---
>         >         :host: localhost
>         >         :port: 2000
>         >         :rails_env: development
>         >         :load_rails: true 
>         >         :worker_dir: lib/workers
>         >
>         >         Your help is *very much* appreciated!
>         >
>         >         Thanks,
>         >         Ger Apeldoorn
>         >
>         >         _______________________________________________ 
>         >         Backgroundrb-devel mailing list
>         >         Backgroundrb-devel at rubyforge.org
>         >
>         http://rubyforge.org/mailman/listinfo/backgroundrb-devel
>         >
> 


More information about the Backgroundrb-devel mailing list