[Backgroundrb-devel] Using BackgrounDRb to replace nested loops?

Jacob Patton jacob.patton at gmail.com
Tue Jul 18 14:24:58 EDT 2006

Hi Ezra,

Thanks for your advice regarding using BackgrounDRb to handle long- 
running emailing processes for my blog application.

I'm having a little trouble getting BackgrounDRb to work--I'm just  
using it to post a message to the logs for now, to make sure I can  
get the code running.

My questions are inline:

> [You said:] I think you would be best served by creating a worker  
> class that did the compilation of messages and sent the emails in  
> the backgroundrb server. I also think that every 5 or 10 minutes is  
> real time enough for most things like this. So you might be better  
> served by building and sending out the email digests at intervals  
> and not with every time a post gets updated.
> So since you need to use ActionMailer, which in turn needs  
> ActionView, you will want to pull most of rails into your drb  
> server so you can make all this happen. So add this line to your  
> script/backgroundrb/start script at the top after the boot.rb  
> require line:
> require File.dirname(__FILE__) + "/../../config/environment.rb"

I've done this...

> Then build a worker class that does the processing and sending of  
> emails in the do_work method.
> class EmailWorker < BackgrounDRb::Rails
>   def do_work(args)
>      # loop over emails and build digest
>      # loop over subscribers and send email
>      #
>   end
> end

I did this, too, but my file looks like:

# in lib/workers/checker_worker.rb

class CheckerWorker < BackgrounDRb::Rails

   def do_work(args)
     logger.debug "BackgrounDRb run at #{Time.now}"


> You will need a cron job to fire off this workers method every 5 or  
> 10 minutes like this:
> #!/usr/bin/env ruby
> require "drb"
> DRb.start_service
> MiddleMan = DRbObject.new(nil, "druby://localhost:22222")

Here is the file I'm using

# in lib/checker.rb

#!/usr/bin/env ruby
require "drb"
MiddleMan = DRbObject.new(nil, "druby://localhost:22222")
MiddleMan.new_worker(:class => :checker_worker, :ttl => 600)

I think I've set up everything correctly, and that by running  
checker.rb by typing ruby checker.rb while within the lib directory,  
the BackgrounDRb object should fire, and the debug message should be  
posted to the log.

When I run the command, though, I get this error message:

(druby://localhost:22222) /usr/local/lib/ruby/gems/1.8/gems/ 
lib/active_support/dependencies.rb:100:in `const_missing':  
uninitialized constan
t CheckerWorker (NameError)

Can you, Ezra, or anyone else help me discover where I've gone wrong?

Thanks very much for your help,

Jacob Patton

More information about the Backgroundrb-devel mailing list