Yes, thank you! I had read about the optional 2nd argument<br>but misunderstood its usefulness. It's working now. But I also<br>learned that the return result is not just my string but a hash<br>containing my string in the "data" hash member. <br><br>Rog<br><br><b><i>Brian Morearty <brian@morearty.org></i></b> wrote:<blockquote class="replbq" style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"> <div>Sorry, I meant to reply-all. Here's what I wrote:</div> <div> </div> <div>Hello Rogelio,<br> <br>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.<br> <br> To make a synchronous call, pass "true" as the 2nd argument to your worker:<br> <br> res = MiddleMan.worker(:pdfmaker_worker, jk).getres(nil, true)<br> <br>In this example I used nil for the first argument because
your getres function doesn't take an argument.<br> <br>For more info see <a href="http://backgroundrb.rubyforge.org/rails/index.html">http://backgroundrb.rubyforge.org/rails/index.html</a> and read the section "Invoke a method on worker and get results."<br> <br> - Brian Morearty<br> </div> <div><br><br> </div> <div class="gmail_quote">On Fri, Apr 18, 2008 at 11:07 AM, Roggie Boone <<a href="mailto:rogboone@yahoo.com">rogboone@yahoo.com</a>> wrote:<br> <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">Hi,<br><br>I'm new to BackgroundRB and am having some trouble figuring<br>out what must be a simple thing. I'm in time crunch where I<br> need my Rails app to generate PDF files on the fly for my website<br>users. But before I leap into that, I'm trying to get familiar with<br>the basics. So I have this worker in my rails app lib/worker
folder:<br>==============<br> class PdfmakerWorker < BackgrounDRb::MetaWorker<br> set_worker_name :pdfmaker_worker<br> set_no_auto_load(true)<br> def create(args = nil)<br> # this method is called, when worker is loaded for the first time<br> register_status(:cnt => 0)<br> 1.upto 100000000 do |x|<br> if x % 1000 == 0<br> register_status(:cnt => x)<br> end<br> end<br> #exit<br> end<br><br> def getres<br> res = "Just a test"<br> return res<br> end<br>end<br><br>============================================================<br><br>I've written a simple program to test that worker and it is as follows:<br><br>jk = MiddleMan.new_worker(:worker =>
:pdfmaker_worker, :job_key => "123", :data => nil)<br> <br>sleep (5)<br><br>count = 0<br><br>while count < 1 <br> pct = MiddleMan.ask_status(:worker => :pdfmaker_worker, :job_key => jk)<br> sleep(2)<br> puts "Count is: " + (pct[:cnt]).to_s<br> <br> res = MiddleMan.worker(:pdfmaker_worker, jk).getres<br> puts "Res is: " + res.to_s<br>end<br>============================================================<br><br>I run script/console and load the above program. The worker counts up<br>to 10000000 and my little test program repeatedly queries the worker<br> and writes "Count is <whatever>" to the screen as it should.<br><br>However, when it get to my custom method "getres" in the last<br>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<br> something simple, but I don't see why. <br><br>Here is a
sample output of one iteration of the simple program:<br>================<br>Count is: 970000000<br>{:type=>:do_work, :worker=>:pdfmaker_worker, :worker_method=>:getres, :job_key=>"123"}<br> Res is: <br>{:type=>:get_status, :worker=>:pdfmaker_worker, :job_key=>"123"}<br>================<br><br>It looks like the call to "getres" is being recognized, but I'm obviously<br>missing some critical link.<br> <br>My setup:<br><br>Ubuntu 7.10<br>Ruby 1.8.6<br>Rails 2.0.2<br>BackgroundRB (been through several versions, latest of <br>which was retrieved via svn on 4/17/08 and I updated the<br>backgroundrb script as per install guidelines)<br> <br>Thanks in advance for your help.<br><br>Rogelio<br> <div class="WgoR0d"><br> <div> </div><hr size="1"> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ" target="_blank">Try it now.</a>
<div></div><div></div></div><br>_______________________________________________<br>Backgroundrb-devel mailing list<br><a href="mailto:Backgroundrb-devel@rubyforge.org">Backgroundrb-devel@rubyforge.org</a><br><a href="http://rubyforge.org/mailman/listinfo/backgroundrb-devel" target="_blank">http://rubyforge.org/mailman/listinfo/backgroundrb-devel</a><br> </blockquote></div><br><br clear="all"><br>-- <br>Brian </blockquote><br><p> 
<hr size=1>Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. <a href="http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ "> Try it now.</a>