[Backgroundrb-devel] Problems running backgroundrb
John Wells
lists at sourceillustrated.com
Wed Feb 13 09:20:41 EST 2008
On Feb 12, 2008 9:03 PM, hemant <gethemant at gmail.com> wrote:
> On Tue, Feb 12, 2008 at 12:05 AM, John Wells
>
> <lists at sourceillustrated.com> wrote:
> >
> > On Feb 11, 2008 1:28 PM, hemant <gethemant at gmail.com> wrote:
> > > On Mon, Feb 11, 2008 at 8:20 PM, John Wells <lists at sourceillustrated.com> wrote:
> > > > On Feb 11, 2008 5:03 AM, hemant kumar <gethemant at gmail.com> wrote:
> > > > >
> > > > > On Mon, 2008-02-11 at 00:55 -0800, Alex Soto wrote:
> > > > > > does require 'lib/formatters' work?
> > > > > >
> > > > > >
> > > > > > On Feb 10, 2008, at 10:11 PM, John Wells wrote:
> > > > > >
> > > > > > > Hi guys,
> > > > > > >
> > > > > > > New to backgroundrb, and I like it very much conceptually, but I'm
> > > > > > > struggling to get it to run successfully. I started with trunk, but
> > > > > > > was getting a very strange gem require error when starting a worker
> > > > > > > (though it wasn't telling me which gem was missing)....see here:
> > > > > > > http://pastie.caboo.se/150225
> > > > >
> > > > > Its not complaining about any missing gems, rather its not able to load
> > > > > workers defined inside lib/workers directory. You must define at least
> > > > > one worker, before you can start bdrb. In case, you have already defined
> > > > > a worker, Can we have a look at the code of your worker?
> > > >
> > > > Thanks for your help. Sure thing...the code is below. However, I'm
> > > > very curious...how did you determine this was the problem? Just so I
> > > > know what to look for in the future.
> > >
> > > Because, when I saw error at:
> > >
> > > http://pastie.caboo.se/150225
> > >
> > > It clearly says thats start_worker is failing on 114 line. Generally
> > > this happens, when bdrb is not able to load a particular worker file.
> > > Also, you see empty string "gem_original_require': no such file to
> > > load -- (LoadError)" because bdrb is not able to get name of worker
> > > file to load correctly.
> > >
> > >
> > >
> > > >
> > > > ===== controller that instantiates worker =====
> > > > class Admin::BatchController < Admin::ApplicationController
> > > >
> > > > def initialize
> > > > super
> > > > @formats = GW::BatchListing::ListingRow.formats
> > > > @part_of = :admin
> > > > end
> > > >
> > > > def get_progress
> > > > if request.xhr?
> > > > progress_percent = MiddleMan.get_worker(session[:job_key]).progress
> > > > render :update do |page|
> > > > page.call('progressPercent', 'progressbar', progress_percent)
> > > > page.redirect_to( :action => 'done') if progress_percent >= 100
> > > > end
> > > > else
> > > > redirect_to :action => 'index'
> > > > end
> > > > end
> > > >
> > > > def done
> > > > errors = "DONE " + MiddleMan.get_worker(session[:job_key]).errors
> > > > if errors.size > 0
> > > > flash[:notice] = errors.join("<br/>")
> > > > else
> > > > flash[:notice] = "Successful load."
> > > > end
> > > > MiddleMan.delete_worker(session[:job_key])
> > > > end
> > > >
> > > > def add
> > > > @user = User.find(params[:id])
> > > > @cats = Category.find(:all, :conditions=>"parent_id is null")
> > > > if request.post?
> > > > listings = params[:listings]
> > > > content_type = listings.content_type.chomp
> > > > if "application/zip"!=content_type and
> > > > "application/x-zip-compressed"!=content_type
> > > > flash[:notice] =
> > > > "Only files of type application/zip " +
> > > > "and application/x-zip-compressed " +
> > > > "can be used. You uploaded #{content_type}."
> > > > else
> > > > # write out to tmp file
> > > > tmpfile = "/tmp/#{rand 500000}.zip"
> > > > open(tmpfile, "w") do |f|
> > > > f << listings.read
> > > > end
> > > > parser =
> > > > GW::BatchListing::ListingParser.new(params[:format],
> > > > params[:listing_type],
> > > > @user)
> > > > session[:job_key] =
> > > > MiddleMan.new_worker(:class => :foo_worker,
> > > > :args => parser)
> > > > end
> > > > end
> > > > end
> > > > end
> > > >
> > >
> > > There are couple of problems with above code, for example,
> > > MiddleMan.get_worker is not defined. To get an idea about, which
> > > methods are defined for MiddleMan, have a look at,
> > >
> > > http://backgroundrb.rubyforge.org/classes/BackgrounDRb/WorkerProxy.html
> > >
> > > Also, you should read README file that comes with plugin.
> > >
> > > > ===== and the worker itself =====
> > > > class BatchImportWorker < BackgrounDRb::MetaWorker
> > > > attr_reader :progress
> > > > attr_reader :errors
> > > > set_worker_name :batch_import_worker
> > > >
> > > > def create(args = nil)
> > > > # this method is called, when worker is loaded for the first time
> > > > end
> > > >
> > > > def do_work(parser)
> > > > @progress = 0
> > > > @errors = parser.process(tmpfile)
> > > > end
> > > > end
> > >
> > > Well, I find no problems with above worker code, and it should load.
> > > Create a fresh rails app and see if bdrb works there.
> >
> >
> > Ok, sorry... I was working from the old InfoQ article by Ezra and the
> > api docs. I probably made some bad assumptions there...I will take a
> > hard look and try it again.
> >
> > Thanks for your help!
>
> Just catching up on this. So, did you manage to get it work after
> reading latest docs?
> If yes, can you tell us, why bdrb was not able to load your worker?
>
It was a number of small little errors, and some big ones. Perhaps the
most damning was:
@errors = parser.process(tmpfile)
You'll note tmpfile doesn't exist in this context ;) That would cause a problem.
I have my solution working now and it's working well. I really
appreciate your help.
My biggest hurdle with backgroundrb was the fact that I have some very
complicated business rules taking place on the brdb side of things,
and without an easy way to step through these with a debugger, lots of
things can go wrong and it makes life more difficult. Running
script/backgroundrb without arguments and using puts and inspect
helps, but hooking to it with a debugger so that one could inspect
variables, etc would be extremely useful. I started going down the
path of getting NetBeans' debugger to work with it, but quickly
realized it was going to take more time than I had given my current
project.
Anyway, thanks very much for your help!
John
More information about the Backgroundrb-devel
mailing list