[Backgroundrb-devel] Problems running backgroundrb

John Wells lists at sourceillustrated.com
Mon Feb 11 09:50:30 EST 2008


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.

===== 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

===== 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


More information about the Backgroundrb-devel mailing list