[Backgroundrb-devel] Using BackgrounDRb to replace nested loops?
jacob.patton at gmail.com
Mon Jul 17 10:09:42 EDT 2006
Ezra thanks for your help and advice. I'll try out the steps you
suggest, and I'll report back to the list.
On Jul 13, 2006, at 11:11 PM, Ezra Zygmuntowicz wrote:
> Answers inline:
> On Jul 13, 2006, at 5:22 PM, Jacob Patton wrote:
>> In response to my Rails Weenie post today, someone mentioned that
>> I try BackgrounDRb to help take the strain off my application.
>> 1: http://rails.techno-weenie.net/question/2006/7/13/nested-loops-
>> I've just tried to install and use BackgrounDRb with my app, but I'm
>> afraid that I'm not too versed in running processes like these, and I
>> can't get the caching to work--I get this error: private method
>> `cache' called for #<BackgrounDRb::MiddleMan:
> I apologize for this. A recent change introduced this bug. Please
> svn up or co the plugin again and try again. Caching will work as
> advertised now. But I don't think caching is the answer to your
> 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"
> 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
> 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"
> MiddleMan = DRbObject.new(nil, "druby://localhost:22222")
> # setting :ttl to 600 seconds/10 minutes. Make sure you set this
> for long enough time for your worker to finish the emails
> # but you need to set this so the workers will get garbage
> collected after they are done.
> MiddleMan.new_worker(:class => :email_worker, :ttl => 600)
> See if this gets you started and ask if you get stuck.
>> <snip code>
>> Jacob Patton
>> Backgroundrb-devel mailing list
>> Backgroundrb-devel at rubyforge.org
More information about the Backgroundrb-devel