[Backgroundrb-devel] Strange behaviour (worker only running on 3 or more attempts)

Iain iain.adams.1985 at googlemail.com
Thu Aug 14 07:41:24 EDT 2008

Dear Mailing List,

I am trying to use backgroundRB to process an uploaded CSV file and save 
it in the database. I have successfully done this, with only one problem 
that seems very unusual. After starting the server, it takes three tries 
before my script is run.

For example, in my controller I have the code:

def authenticate_import
         @dataset = Dataset.new params[:dataset]
         @dataset.campaign = @campaign
         #Check the normal info is valid
         if !@dataset.valid?
            render :action => 'import'
            #Start the worker
             MiddleMan.worker(:dataset_worker).async_process(:arg => 
            @progress = 
             render :action => 'progress'

This progress is then fed into a progress bar which periodically updates 
itself by calling:

@progress = MiddleMan.worker(:dataset_worker).ask_result(:progress)

The problem is that the first two times I attempt uploading (.i.e 
calling this code) nothing happens. No output happens at all. After that 
every call works fine and all the debugging info etc is written to the 
log files etc, everything is saved fine.

Does anyone have any ideas why this may be happening? any help would be 
greatly appreciated

My worker is below:

class DatasetWorker < BackgrounDRb::MetaWorker
  set_worker_name :dataset_worker

  def create(args = nil)
      logger.info "Dataset Worker setup"

  def process(dataset)
    thread_pool.defer(:process_csv, dataset)
  def process_csv(dataset)
    logger.info "Started to Process Dataset (title: #{dataset.name})"
    cache[:progress] = 0.00
    .  #Code to save stuff into database and updating cache[:progress]


More information about the Backgroundrb-devel mailing list