Yes, thank you! I had read about the optional 2nd argument
but misunderstood its usefulness. It's working now. But I also
learned that the return result is not just my string but a hash
containing my string in the "data" hash member.
Rog
Brian Morearty <[EMAIL PROTECTED]> wrote: Sorry, I meant to reply-all. Here's
what I wrote:
Hello Rogelio,
If you want a return value you have to call it synchronously. The default call
is asynchronous--because after all, it's a background call. That's why you're
getting nil back.
To make a synchronous call, pass "true" as the 2nd argument to your worker:
res = MiddleMan.worker(:pdfmaker_worker, jk).getres(nil, true)
In this example I used nil for the first argument because your getres function
doesn't take an argument.
For more info see http://backgroundrb.rubyforge.org/rails/index.html and read
the section "Invoke a method on worker and get results."
- Brian Morearty
On Fri, Apr 18, 2008 at 11:07 AM, Roggie Boone <[EMAIL PROTECTED]> wrote:
Hi,
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
set_no_auto_load(true)
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)
end
end
#exit
end
def getres
res = "Just a test"
return res
end
end
============================================================
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)
sleep(2)
puts "Count is: " + (pct[:cnt]).to_s
res = MiddleMan.worker(:pdfmaker_worker, jk).getres
puts "Res is: " + res.to_s
end
============================================================
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.
Rogelio
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
_______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel
--
Brian
---------------------------------
Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now._______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel