[Backgroundrb-devel] [ANN] New release!

Ezra Zygmuntowicz ezmobius at gmail.com
Mon Jun 12 18:08:56 EDT 2006

Hey Folks-

	I have just pushed a new release of BackgrounDRb to rubyforge. It  
has some nice new features to allow for usage of your ActiveRecord  
Models within your worker classes. I also added a config file for  
setting hosts and ports and if you want to load rails or not.

	Please have a look and let me know if anyone runs into any issues.  
If you already have an older version installed then you need to  
delete the script/backgroundrb dir from your rails app and reinstall  
the plugin. You can leave your lib/workers dir alone and it won't get  
clobbered. Once you have run rake backgroundrb:setup with the new  
plugin you need to look into config/backlgroundrb.yml for your  
settings. The defaults are fine but you need to be aware of them. You  
can set whether ActiveRecord connects to your development or  
production databases in the conf file. It will use your existing  
database.ymkl to make the connection.

         This is a new improved way to create your worker classes.
         You just need to inherit from BackgrounDRb::Rails and define
         a do_work(args) method. This method will automatically get
         called in its own thread when you create a new worker from
         rails. So when you say:

	MiddleMan.new_worker :class => :foo_worker, :args => "Hello!"

	The "Hello" argument gets sent to your do_work method.

	# 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 if you set load_rails to true in the
	# config file. You also get @logger inside of this class by default.
	class FooWorker < BackgrounDRb::Rails

	  def do_work(args)
	    # This method is called in it's own new thread when you
	    # call new worker. args is set to :args.
             @logger.debug Post.find(:all).to_yaml


	So you no longer have to deal with THreads yourself. Just inherit  
from the right class and this is taken care of for you.


More information about the Backgroundrb-devel mailing list