Hi, All It appears that when you enque a task, backgroundrb doesn''t pass the "arg" parameter when running the enqued method. This is my worker: class NotificationWorker < BackgrounDRb::MetaWorker set_worker_name :notification_worker def create(args = nil) logger.info("Args: #{args}") end def send_warranty_notice(data) logger.info "Sending warranty notice id is #{data}" end end Here''s how I call it from IRB MiddleMan.worker(:notification_worker).enq_send_warranty_notice(:arg=>"asdf",:job_key=>Time.now.to_s,:scheduled_at => Time.now + 3.seconds) The "send_warranty_notice" method gets called but the parameter passed (data) is nil. Calling async_method works fine: MiddleMan.worker(:notification_worker).async_send_warranty_notice(:arg=>"asdf") prints out "Sending warranty notice id is asdf" in the drb log. Also I noticed that on the following page http://backgroundrb.rubyforge.org/workers/ the following text MiddleMan(:hello_worker).enq_some_task(:arg => "hello_world",:job_key => "boy") should read MiddleMan.worker(:hello_worker).enq_some_task(:arg => "hello_world",:job_key => "boy") ... unless I am missing something? Any suggestions on how I can fix the arg passing problem? Regards Justin Wood -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090313/c0e75852/attachment.html>
Here''s the usage When creating a worker the :create method gets called with args you pass this in with the :data argument to new_worker MiddleMan.new_worker( :worker => :notification_worker, :worker_key => ''test'', :data => "some argument" ) a bit confusing on the names but it is documented. The create method says args even though you pass it in as data When sending args to your method after you worker is created use something like MiddleMan.worker( :notification_worker, ''test'').enq_some_task( :arg => "some argument" ) Hope that helps Samer Masry www.dryblis.com On Mar 12, 2009, at 9:22 PM, Justin Wood wrote:> Hi, All > > It appears that when you enque a task, backgroundrb doesn''t pass the > "arg" parameter when running the enqued method. > > This is my worker: > > class NotificationWorker < BackgrounDRb::MetaWorker > set_worker_name :notification_worker > > def create(args = nil) > logger.info("Args: #{args}") > end > > def send_warranty_notice(data) > logger.info "Sending warranty notice id is #{data}" > end > end > > Here''s how I call it from IRB > > MiddleMan > .worker > (:notification_worker > ).enq_send_warranty_notice > (:arg=>"asdf",:job_key=>Time.now.to_s,:scheduled_at => Time.now + > 3.seconds) > > The "send_warranty_notice" method gets called but the parameter > passed (data) is nil. > > > Calling async_method works fine: > > MiddleMan > .worker(:notification_worker).async_send_warranty_notice(:arg=>"asdf") > > prints out "Sending warranty notice id is asdf" in the drb log. > > Also I noticed that on the following page http://backgroundrb.rubyforge.org/workers/ > the following text > MiddleMan(:hello_worker).enq_some_task(:arg => > "hello_world",:job_key => "boy") > > should read > > MiddleMan.worker(:hello_worker).enq_some_task(:arg => > "hello_world",:job_key => "boy") ... unless I am missing something? > > > > Any suggestions on how I can fix the arg passing problem? > > > Regards > Justin Wood > > > > > > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090312/1fd54ca0/attachment.html>
Hi, Samer Thanks for the quick reply. I changed things a bit and ran this>>MiddleMan.new_worker(:worker=>:notification_worker,:worker_key=>''testkey'',:data=>"data arguement") => "testkey">>MiddleMan.worker(:notification_worker,''testkey'').enq_send_warranty_notice(:job_key=>Time.now.to_s,:arg => "asdf",:scheduled_at => Time.now + 3.second) => true ... but the arg is still not being passed. My understanding of new_worker is it explictly creates a worker for you that you can refer to by the key, so If I do this: MiddleMan.worker(:notification_worker,''testkey'') I''m getting the worker I created above but when I call this: MiddleMan.worker(:notification_worker) I''m getting the default worker that was created at startup. Regardless of how the worker is created the "arg" parameter is still not being passed when it gets invoked to do enqued work. Going through the code ... I can''t figure out how it gets invoked. Thanks Justin On Fri, Mar 13, 2009 at 5:55 PM, Samer Masry <enzodm at gmail.com> wrote:> Here''s the usage > When creating a worker the :create method gets called with args you pass > this in with the :data argument to new_worker > > MiddleMan.new_worker( :worker => :notification_worker, :worker_key => > ''test'', :data => "some argument" ) > > a bit confusing on the names but it is documented. The create method says > args even though you pass it in as data > > When sending args to your method after you worker is created use something > like > > MiddleMan.worker( :notification_worker, ''test'').enq_some_task( :arg => > "some argument" ) > > Hope that helps > Samer Masry > www.dryblis.com > > On Mar 12, 2009, at 9:22 PM, Justin Wood wrote: > > Hi, All > > It appears that when you enque a task, backgroundrb doesn''t pass the "arg" > parameter when running the enqued method. > > This is my worker: > > class NotificationWorker < BackgrounDRb::MetaWorker > set_worker_name :notification_worker > > def create(args = nil) > logger.info("Args: #{args}") > end > > def send_warranty_notice(data) > logger.info "Sending warranty notice id is #{data}" > end > end > > Here''s how I call it from IRB > > MiddleMan.worker(:notification_worker).enq_send_warranty_notice(:arg=>"asdf",:job_key=>Time.now.to_s,:scheduled_at > => Time.now + 3.seconds) > > The "send_warranty_notice" method gets called but the parameter passed > (data) is nil. > > > Calling async_method works fine: > > > MiddleMan.worker(:notification_worker).async_send_warranty_notice(:arg=>"asdf") > > prints out "Sending warranty notice id is asdf" in the drb log. > > Also I noticed that on the following page > http://backgroundrb.rubyforge.org/workers/ the following text > > MiddleMan(:hello_worker).enq_some_task(:arg => "hello_world",:job_key => "boy") > > should read > > MiddleMan.worker(:hello_worker).enq_some_task(:arg => "hello_world",:job_key => "boy") ... unless I am missing something? > > > Any suggestions on how I can fix the arg passing problem? > > > Regards > Justin Wood > > > > > > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel > > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090313/8659213c/attachment-0001.html>
On Fri, Mar 13, 2009 at 11:57 AM, Justin Wood <justin.wood at trifectagis.com> wrote:> Hi, Samer > > Thanks for the quick reply.?? I changed things a bit and ran this > >>> >>> MiddleMan.new_worker(:worker=>:notification_worker,:worker_key=>''testkey'',:data=>"data >>> arguement") > => "testkey" >>> >>> MiddleMan.worker(:notification_worker,''testkey'').enq_send_warranty_notice(:job_key=>Time.now.to_s,:arg >>> => "asdf",:scheduled_at => Time.now + 3.second) > => true > > ... but the arg is still not being passed. > > My understanding of new_worker is it explictly creates a worker for you that > you can refer to by the key, so > > If I do this: > > ????? MiddleMan.worker(:notification_worker,''testkey'') > > I''m getting the worker I created above but when?I call this: > > ???? MiddleMan.worker(:notification_worker) > > I''m getting the default worker that was created at startup. > > Regardless of how the worker is created the "arg" parameter is still not > being passed when it gets invoked to do enqued work.?? Going through the > code ... I can''t figure out how it gets invoked. >Well whatever you pass to enq_xxx method gets marshalled to database and gets unmarshalled from table when the task is scheduled inside worker. Can you paste your worker code?
Hi, Hemant Ah ok. Found out where it was making the call in in meta_worker and saw the args coming back nil from load_data. So I ran this in IRB>> job=BdrbJobQueue.find(:first,:conditions => [" worker_name = ? AND taken= ? AND scheduled_at <= ? ", "notification_worker", 0, Time.now.utc ]) => #<BdrbJobQueue id: 53, args: "\\004\\010\"\\011asdf", worker_name: "notification_worker", worker_method: "asdf", job_key: "Fri Mar 13 16:14:48 +1300 2009", taken: 0, finished: 0, timeout: nil, priority: nil, submitted_at: "2009-03-13 03:14:48", started_at: nil, finished_at: nil, archived_at: nil, tag: nil, submitter_info: nil, runner_info: nil, worker_key: "", scheduled_at: "2009-03-13 03:14:51">>> job.args=> "\\004\\010\"\\011asdf">> Marshal.load(job.args)TypeError: incompatible marshal file format (can''t be read) format version 4.8 required; 92.48 given from (irb):10:in `load'' from (irb):10 So the problem is with marshalling ... double checked that by putting a logger statement into BdrbServerHelper''s load_data like so: ... rescue error_msg = $!.message logger.error("Error marshaling data: #{data} #{error_msg}) #added if error_msg =~ /^undefined\ .+\ ([A-Z].+)/ .... and got the same error message. Having something going to the log in the rescue there would be a useful addition. I''m using Postgres 8.3.1 (database in utf8) on Ubuntu found someone else that encountered a marshalling error here: http://blade.nagaokaut.ac.jp/ruby/ruby-talk/116099 Looks like a ruby/Postgres issue? I''ll have a look see if I can sort this out but any advice you could give me would be much appreciated. Thanks Justin On Fri, Mar 13, 2009 at 8:58 PM, hemant <gethemant at gmail.com> wrote:> On Fri, Mar 13, 2009 at 11:57 AM, Justin Wood > <justin.wood at trifectagis.com> wrote: > > Hi, Samer > > > > Thanks for the quick reply. I changed things a bit and ran this > > > >>> > >>> > MiddleMan.new_worker(:worker=>:notification_worker,:worker_key=>''testkey'',:data=>"data > >>> arguement") > > => "testkey" > >>> > >>> > MiddleMan.worker(:notification_worker,''testkey'').enq_send_warranty_notice(:job_key=>Time.now.to_s,:arg > >>> => "asdf",:scheduled_at => Time.now + 3.second) > > => true > > > > ... but the arg is still not being passed. > > > > My understanding of new_worker is it explictly creates a worker for you > that > > you can refer to by the key, so > > > > If I do this: > > > > MiddleMan.worker(:notification_worker,''testkey'') > > > > I''m getting the worker I created above but when I call this: > > > > MiddleMan.worker(:notification_worker) > > > > I''m getting the default worker that was created at startup. > > > > Regardless of how the worker is created the "arg" parameter is still not > > being passed when it gets invoked to do enqued work. Going through the > > code ... I can''t figure out how it gets invoked. > > > > Well whatever you pass to enq_xxx method gets marshalled to database > and gets unmarshalled from table when the task is scheduled inside > worker. Can you paste your worker code? >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090314/e19cb0b8/attachment.html>
Hi, All Appreciate all the assistance, turns out this is a problem resulting from Rails <= 2.1.1 and Postgres (to do with the way binary fields are escaped) I upgraded Rails and it works. Thanks Justin On Sat, Mar 14, 2009 at 11:07 AM, Justin Wood <justin.wood at trifectagis.com>wrote:> Hi, Hemant > > Ah ok. Found out where it was making the call in in meta_worker and saw > the args coming back nil from load_data. So I ran this in IRB > > >> job=BdrbJobQueue.find(:first,:conditions => [" worker_name = ? AND taken > = ? AND scheduled_at <= ? ", "notification_worker", 0, Time.now.utc ]) > => #<BdrbJobQueue id: 53, args: "\\004\\010\"\\011asdf", worker_name: > "notification_worker", worker_method: "asdf", job_key: "Fri Mar 13 16:14:48 > +1300 2009", taken: 0, finished: 0, timeout: nil, priority: nil, > submitted_at: "2009-03-13 03:14:48", started_at: nil, finished_at: nil, > archived_at: nil, tag: nil, submitter_info: nil, runner_info: nil, > worker_key: "", scheduled_at: "2009-03-13 03:14:51"> > >> job.args > => "\\004\\010\"\\011asdf" > >> Marshal.load(job.args) > TypeError: incompatible marshal file format (can''t be read) > format version 4.8 required; 92.48 given > from (irb):10:in `load'' > from (irb):10 > > So the problem is with marshalling ... double checked that by putting a > logger statement into BdrbServerHelper''s load_data like so: > > ... > rescue > error_msg = $!.message > logger.error("Error marshaling data: #{data} #{error_msg}) > #added > if error_msg =~ /^undefined\ .+\ ([A-Z].+)/ > .... > > and got the same error message. Having something going to the log in the > rescue there would be a useful addition. > > I''m using Postgres 8.3.1 (database in utf8) on Ubuntu found someone else > that encountered a marshalling error here: > > http://blade.nagaokaut.ac.jp/ruby/ruby-talk/116099 > > Looks like a ruby/Postgres issue? I''ll have a look see if I can sort > this out but any advice you could give me would be much appreciated. > > Thanks > Justin > > > > On Fri, Mar 13, 2009 at 8:58 PM, hemant <gethemant at gmail.com> wrote: > >> On Fri, Mar 13, 2009 at 11:57 AM, Justin Wood >> <justin.wood at trifectagis.com> wrote: >> > Hi, Samer >> > >> > Thanks for the quick reply. I changed things a bit and ran this >> > >> >>> >> >>> >> MiddleMan.new_worker(:worker=>:notification_worker,:worker_key=>''testkey'',:data=>"data >> >>> arguement") >> > => "testkey" >> >>> >> >>> >> MiddleMan.worker(:notification_worker,''testkey'').enq_send_warranty_notice(:job_key=>Time.now.to_s,:arg >> >>> => "asdf",:scheduled_at => Time.now + 3.second) >> > => true >> > >> > ... but the arg is still not being passed. >> > >> > My understanding of new_worker is it explictly creates a worker for you >> that >> > you can refer to by the key, so >> > >> > If I do this: >> > >> > MiddleMan.worker(:notification_worker,''testkey'') >> > >> > I''m getting the worker I created above but when I call this: >> > >> > MiddleMan.worker(:notification_worker) >> > >> > I''m getting the default worker that was created at startup. >> > >> > Regardless of how the worker is created the "arg" parameter is still not >> > being passed when it gets invoked to do enqued work. Going through the >> > code ... I can''t figure out how it gets invoked. >> > >> >> Well whatever you pass to enq_xxx method gets marshalled to database >> and gets unmarshalled from table when the task is scheduled inside >> worker. Can you paste your worker code? >> > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090315/cd5929cd/attachment-0001.html>
Ah, We can put this in FAQ. 2009/3/15 Justin Wood <justin.wood at trifectagis.com>:> Hi, All > > Appreciate all the assistance, turns out this is a problem resulting from > > Rails <= 2.1.1 and Postgres (to do with the way binary fields are escaped) > > I upgraded Rails and it works. > > Thanks > Justin > > On Sat, Mar 14, 2009 at 11:07 AM, Justin Wood <justin.wood at trifectagis.com> > wrote: >> >> Hi, Hemant >> >> Ah ok.?? Found out where it was making the call in in meta_worker and saw >> the args coming back nil from load_data.?? So I ran this in IRB >> >> >> job=BdrbJobQueue.find(:first,:conditions => [" worker_name = ? AND >> >> taken = ? AND scheduled_at <= ? ", "notification_worker", 0, Time.now.utc ]) >> => #<BdrbJobQueue id: 53, args: "\\004\\010\"\\011asdf", worker_name: >> "notification_worker", worker_method: "asdf", job_key: "Fri Mar 13 16:14:48 >> +1300 2009", taken: 0, finished: 0, timeout: nil, priority: nil, >> submitted_at: "2009-03-13 03:14:48", started_at: nil, finished_at: nil, >> archived_at: nil, tag: nil, submitter_info: nil, runner_info: nil, >> worker_key: "", scheduled_at: "2009-03-13 03:14:51"> >> >> job.args >> => "\\004\\010\"\\011asdf" >> >> Marshal.load(job.args) >> TypeError: incompatible marshal file format (can''t be read) >> ??????? format version 4.8 required; 92.48 given >> ??????? from (irb):10:in `load'' >> ??????? from (irb):10 >> >> So the problem is with marshalling ... double checked that by putting a >> logger statement into BdrbServerHelper''s load_data like so: >> >> ... >> rescue >> ??????? error_msg = $!.message >> ??????? logger.error("Error marshaling data:? #{data}? #{error_msg}) >> #added >> ??????? if error_msg =~ /^undefined\ .+\ ([A-Z].+)/ >> .... >> >> and got the same error message.?? Having something going to the log in the >> rescue there would be a useful addition. >> >> I''m using Postgres 8.3.1 (database in utf8) on Ubuntu found someone else >> that encountered a marshalling error here: >> >> http://blade.nagaokaut.ac.jp/ruby/ruby-talk/116099 >> >> Looks like a ruby/Postgres issue? ?? I''ll have a look see if I can sort >> this out but any advice you could give me would be much appreciated. >> >> Thanks >> Justin >> >> >> On Fri, Mar 13, 2009 at 8:58 PM, hemant <gethemant at gmail.com> wrote: >>> >>> On Fri, Mar 13, 2009 at 11:57 AM, Justin Wood >>> <justin.wood at trifectagis.com> wrote: >>> > Hi, Samer >>> > >>> > Thanks for the quick reply.?? I changed things a bit and ran this >>> > >>> >>> >>> >>> >>> >>> MiddleMan.new_worker(:worker=>:notification_worker,:worker_key=>''testkey'',:data=>"data >>> >>> arguement") >>> > => "testkey" >>> >>> >>> >>> >>> >>> MiddleMan.worker(:notification_worker,''testkey'').enq_send_warranty_notice(:job_key=>Time.now.to_s,:arg >>> >>> => "asdf",:scheduled_at => Time.now + 3.second) >>> > => true >>> > >>> > ... but the arg is still not being passed. >>> > >>> > My understanding of new_worker is it explictly creates a worker for you >>> > that >>> > you can refer to by the key, so >>> > >>> > If I do this: >>> > >>> > ????? MiddleMan.worker(:notification_worker,''testkey'') >>> > >>> > I''m getting the worker I created above but when?I call this: >>> > >>> > ???? MiddleMan.worker(:notification_worker) >>> > >>> > I''m getting the default worker that was created at startup. >>> > >>> > Regardless of how the worker is created the "arg" parameter is still >>> > not >>> > being passed when it gets invoked to do enqued work.?? Going through >>> > the >>> > code ... I can''t figure out how it gets invoked. >>> > >>> >>> Well whatever you pass to enq_xxx method gets marshalled to database >>> and gets unmarshalled from table when the task is scheduled inside >>> worker. Can you paste your worker code? >> > > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org