Benjamin H. Bryant
2008-Jan-17 08:46 UTC
[Backgroundrb-devel] Inconsistent Model creation behavior
Hi, I have a relatively simple Worker: (I added the line numbers to the email, they are not in the worker) ##################################################################################### class ImagetestWorker < BackgrounDRb::MetaWorker set_worker_name :imagetest_worker def create(args = nil) end def save_image(args) @newbook = Book.new @newbook.comment = "hello" @newbook.save 14 @newerimage = Image.new 15 @newerimage.user_id = args[:user_id] 16 @newerimage.uploaded_data = args[:temppath] @newerimage.save end end ##################################################################################### It will create and save the Book object without problems. However, it will not create the Image object and instead I receive this error: ##################################################################################### workers/imagetest_worker.rb:15:in `save_image'': You have a nil object when you didn''t expect it! (NoMethodError) You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.[] from /Users/BBryant/Sites/ date_site/trunk/vendor/plugins/backgroundrb/server/meta_worker.rb: 223:in `send'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ server/meta_worker.rb:223:in `process_request'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ server/meta_worker.rb:207:in `receive_data'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ framework/worker.rb:54:in `receive_internal_data'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/BackgrounDRB/ lib/../framework/bin_parser.rb:29:in `call'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/BackgrounDRB/ lib/../framework/bin_parser.rb:29:in `extract'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ framework/worker.rb:52:in `receive_internal_data'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ framework/worker.rb:48:in `handle_internal_messages'' ... 10 levels... from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ framework/packet_master.rb:19:in `run'' from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ server/master_worker.rb:163:in `initialize'' from script/backgroundrb:41:in `new'' from script/backgroundrb:41 #################################################################################### I can create and save an instance of the Image model from a controller without problems. This is driving me crazy. Thanks in advance. Ben
Hi On Jan 17, 2008 2:16 PM, Benjamin H. Bryant <iambenbryant at gmail.com> wrote:> Hi, > > I have a relatively simple Worker: (I added the line numbers to the > email, they are not in the worker) > > ##################################################################################### > > class ImagetestWorker < BackgrounDRb::MetaWorker > > set_worker_name :imagetest_worker > def create(args = nil) > > end > > def save_image(args) > > @newbook = Book.new > @newbook.comment = "hello" > @newbook.save > > 14 @newerimage = Image.new > 15 @newerimage.user_id = args[:user_id] > 16 @newerimage.uploaded_data = args[:temppath] > @newerimage.save > > end > > end > > ##################################################################################### > > It will create and save the Book object without problems. However, it > will not create the Image object and instead I receive this error: > > ##################################################################################### > > workers/imagetest_worker.rb:15:in `save_image'': You have a nil object > when you didn''t expect it! (NoMethodError) > You might have expected an instance of ActiveRecord::Base. > The error occurred while evaluating nil.[] from /Users/BBryant/Sites/ > date_site/trunk/vendor/plugins/backgroundrb/server/meta_worker.rb: > 223:in `send'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > server/meta_worker.rb:223:in `process_request'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > server/meta_worker.rb:207:in `receive_data'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > framework/worker.rb:54:in `receive_internal_data'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/BackgrounDRB/ > lib/../framework/bin_parser.rb:29:in `call'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/BackgrounDRB/ > lib/../framework/bin_parser.rb:29:in `extract'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > framework/worker.rb:52:in `receive_internal_data'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > framework/worker.rb:48:in `handle_internal_messages'' > ... 10 levels... > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > framework/packet_master.rb:19:in `run'' > from /Users/BBryant/Sites/date_site/trunk/vendor/plugins/backgroundrb/ > server/master_worker.rb:163:in `initialize'' > from script/backgroundrb:41:in `new'' > from script/backgroundrb:41 > > #################################################################################### >Ok so you are invoking this task from rails right? Can you show us the code thats being used to invoke above mentioned task? -- 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
On Jan 17, 2008 3:21 PM, Benjamin H. Bryant <iambenbryant at gmail.com> wrote:> Sure, the code in the controller is: > > MiddleMan.ask_work(:worker => :imagetest_worker, :worker_method > => :save_image, :user_id => session[:user_id], :temppath => > params[:newimage][:uploaded_data].path) >It should be: MiddleMan.ask_work(:worker => :imagetest_worker, :worker_method => :save_image, :data => { :user_id => session[:user_id], :temppath => params[:newimage][:uploaded_data].path} ) that :data thing is a must, your arguments aren''t getting passed properly. -- 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