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.
*Home page: http://backgroundrb.rubyforge.org *svn repo: svn://rubyforge.org//var/svn/backgroundrb *Mailing list: http://rubyforge.org/mailman/listinfo/backgroundrb-devel 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. 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 end end So you no longer have to deal with Threads yourself. And you get 'free' access to all your ActiveRecord models. Just inherit from
the right class
and this is taken care of for you.
*Home page: http://backgroundrb.rubyforge.org *svn repo: svn://rubyforge.org//var/svn/backgroundrb *Mailing list: http://rubyforge.org/mailman/listinfo/backgroundrb-devel To install BackgrounDRb you need to follow these steps: 1. Install the plugin in your vendor/plugins directory $ script/plugin install svn://rubyforge.org//var/svn/backgroundrb 2. To install start stop scripts and worker dir: $ rake backgroundrb:setup 3. After you run the setup task take a look in RAILS_ROOT/config/
This is the config file for the drb server where you can set the
port and host
as well as whether or not to load your rails models for use in a
4. There are now rake tasks to start and stop the drb server. $ rake backgroundrb:start and $ rake backgroundrb:stop *** If you are on windows you can't use the rake tasks to start and
stop the server.
Instead use the script directly but don’t supply the -d option. In
windows there is
no fork so until I get time to create a windows service you need to
have a console
windows open with backgroundrb running in n it.
> ruby script/backgroundrb/start # start the server on port 11111 in the background. $ script/backgroundrb/start -p 11111 -d 5. There is also a worker class generator. Description: The worker generator creates stubs for a new worker. The generator takes a worker name as its argument. The worker
name may be
given in CamelCase or under_score and should not be suffixed
The generator creates a worker class in lib/workers and a test
Example: ./script/generate worker Tail This will create an Tail worker: Model: lib/workers/tail_worker.rb Test: test/unit/tail_worker_test.rb