[Backgroundrb-devel] [Newbie] Trouble with methods?

Roggie Boone rogboone at yahoo.com
Fri Apr 18 14:07:11 EDT 2008


I'm new to BackgroundRB and am having some trouble figuring
out what must be a simple thing.  I'm in  time crunch where I
need my Rails app to generate PDF files on the fly for my website
users.  But before I leap into that, I'm trying to get familiar with
the basics.  So I have this worker in my rails app lib/worker folder:
class PdfmakerWorker < BackgrounDRb::MetaWorker
  set_worker_name :pdfmaker_worker
  def create(args = nil)
    # this method is called, when worker is loaded for the first time
      register_status(:cnt => 0)
      1.upto 100000000 do |x|
       if x % 1000 == 0
        register_status(:cnt => x)

  def getres
    res = "Just a test"
    return res


I've written a simple program to test that worker and it is as follows:

jk = MiddleMan.new_worker(:worker => :pdfmaker_worker, :job_key => "123", :data => nil)

sleep (5)

count = 0

while count < 1 
  pct = MiddleMan.ask_status(:worker => :pdfmaker_worker, :job_key => jk)
  puts "Count is: " + (pct[:cnt]).to_s
  res = MiddleMan.worker(:pdfmaker_worker, jk).getres
  puts "Res is: " + res.to_s

I run script/console and load the above program.  The worker counts up
to 10000000 and my little test program repeatedly queries the worker
and writes "Count is <whatever>" to the screen as it should.

However, when it get to my custom method "getres" in the last
two lines of the test program,  the return result for "res" is nil.  The worker doesn't crash, it just appears not to return a result.  I'm sure it's
something simple, but I don't see why.  

Here is a sample output of one iteration of the simple program:
Count is: 970000000
{:type=>:do_work, :worker=>:pdfmaker_worker, :worker_method=>:getres, :job_key=>"123"}
Res is: 
{:type=>:get_status, :worker=>:pdfmaker_worker, :job_key=>"123"}

It looks like the call to "getres" is being recognized, but I'm obviously
missing some critical link.

My setup:

Ubuntu 7.10
Ruby 1.8.6
Rails 2.0.2
BackgroundRB (been through several versions, latest of 
which was retrieved via svn on 4/17/08 and I updated the
backgroundrb script as per install guidelines)

Thanks in advance for your help.


Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080418/ed9dca84/attachment-0001.html 

More information about the Backgroundrb-devel mailing list